• Advertisement

Archived

This topic is now archived and is closed to further replies.

When performance matters...

This topic is 5058 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

...what are the realistic possibilities when choosing a programming language? Assembly language is probably not a good choice. Most people don''t know it or the computer''s architecture well enough to optimize better than the compiler, plus it makes for a less mentally managable program. And then in a few years when a new generation of processors come out... ugh. C is a good choice when speed matters, obviously. C++ is a good choice, so long as you don''t do anything bone headed. So we have C, and C++ which will basically run at the same speed as a program written in C on today''s compilers. What else? C# is a nice language (I really like it). But whether or not it is good for a speed critical app is up in the air at best, I think. Every benchmark comparing C/C++ to C# and Java tells a different story. Some show C# to be within a few percent of natively compiled C/C++, while others show it to be significantly slower than Java, which is shown to be significantly slower than natively compiled C/C++. Some languages seem to offer very good performance, like O''Caml, but I don''t think that these languages offer enough control to really get maximum performance. As an example, if you are writing a program to take advantage of a multi-cpu Opteron, you had better have control over which processes/threads get run on which processor or you are going to kill the multi-cpu performance (since Opteron is NUMA based). I don''t think you can have that kind of control in any language that is garbage collected, can you? I do recall seeing some kind of processor afinity stuff in C#, so maybe it is possible. So we''re back to C and C++. Surely that is not all...

Share this post


Link to post
Share on other sites
Advertisement
There''s no shortages of languages out there. Most of them can produce very fast or slow programs, depending on how you used them. I think the better question to ask yourself is which language is the best fit for your problem domain. This is where the choice of language really matters.

IMHO, chasing after a language for speed is trying to solve a problem that doesn''t exist.

-John

Share this post


Link to post
Share on other sites
quote:
Original post by Teknofreek
There''s no shortages of languages out there. Most of them can produce very fast or slow programs, depending on how you used them. I think the better question to ask yourself is which language is the best fit for your problem domain. This is where the choice of language really matters.

IMHO, chasing after a language for speed is trying to solve a problem that doesn''t exist.

-John


^
|
|
|
|


Share this post


Link to post
Share on other sites
How about you use a language to solve a problem and not just to be fast? The programmer''s mindset is a narrow one in which EVERYTHING must be fast and maximally efficient. Thus for many problems the first choice that springs to mind is "well it has to be fast, C++ it is!" Most end users really don''t care about implementation language. I write for end users above all else, not to look impressive because I chose language X.

Languages are just tools, don''t treat them as anything more. C/C++ is overused nowadays and most people on this forum that are writing games aren''t going to be in a project where they hit the upper bound of performance because of language constraints. I think people take languages too seriously here. In fact, I''d argue some of these games will never be completed and C++''s low-level nature doesn''t help at all. I don''t think language selection matters *that* much as long as you can justify why you are using your language beyond, "well the current meme at GameDev is that C++ is fast and C# is lame." C++ is important to know, but it is by no means the end all of programming languages...thankfully. Don''t fret over language design. You like C#? Use it. You like the templates of C++? Use that.

There is no general advice, it is specific to each problem. People (will in 3 months) pay me for my ability to discern and choose technologies.

Of course I''ll be flamed for posting something that is against groupthink, but such is life.

Share this post


Link to post
Share on other sites
If you can factor your packages/modules/classes appropriately, then you can implement each one in a language that is appropriate for each task.

This requires implementing FFI''s and having multiple toolchains -but is surely better then trying to implement packages in languages not suited for the various tasks.

Share this post


Link to post
Share on other sites
Okay, well I''m not programming for any users, and there is no point at which I can say, "okay, this program is fast enough." I''m writing a chess program for competition with other computer chess programs (amateur hobby). The faster, the better. However, I don''t want to go any lower level than C. Ideally, I''d like to use C#, but I''m not sure yet if it can be competitve with C++. If it can consistently come with 10-20%, I''ll take that. I''m writing a test program to see how it might perform. I found one chess program written in C# on the internet, and the C# program ran at about 22% the speed of Crafty, which is written in C.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You''re only thinking about optimization in the small. Large, project-level performance issues don''t hinge on language nearly so much. I can easily see an *interpreted* language out-performing a compiled language for large, complex applications, for example.

Share this post


Link to post
Share on other sites
quote:
Original post by Russell
Okay, well I''m not programming for any users, and there is no point at which I can say, "okay, this program is fast enough." I''m writing a chess program for competition with other computer chess programs (amateur hobby). The faster, the better. However, I don''t want to go any lower level than C. Ideally, I''d like to use C#, but I''m not sure yet if it can be competitve with C++. If it can consistently come with 10-20%, I''ll take that. I''m writing a test program to see how it might perform. I found one chess program written in C# on the internet, and the C# program ran at about 22% the speed of Crafty, which is written in C.
Where do you get this 22% number? Have you attached a profiler to each program? What are the bottlenecks in each program?

Share this post


Link to post
Share on other sites
quote:
Original post by flangazor
Where do you get this 22% number? Have you attached a profiler to each program? What are the bottlenecks in each program?


I compiled both programs and ran both of them (searching a chess position). Crafty finished in 0.8 seconds, the C# program finished in about 3.6 seconds. It was just a quick test, but it didn''t look promising. Maybe there are some huge, uneccessary bottlenecks and things that can be improved, but getting close to 100% from 22% usually isn''t easy.

Share this post


Link to post
Share on other sites
So you took a well-known native version and pitted it against a quick C# implementation and was disappointed when it didn''t measure up?

Share this post


Link to post
Share on other sites
quote:
Original post by antareus
So you took a well-known native version and pitted it against a quick C# implementation and was disappointed when it didn''t measure up?
I wouldn''t call it a "quick C# implementation." Someone else spent several months implementing it. I only spent a few minutes compiling it and running well known computer chess benchmarks to test the speed of it. If you want to try it yourself, download the source code: #Chess. Compare that with Crafty. Crafty isn''t even a particuarly fast program as far as dumb bean counting goes. I could write something a good deal faster if speed is all we are testing (and not how well it plays chess).

Share this post


Link to post
Share on other sites
Fortran is supposed to be good for numerical performance. I don''t know much about it, but I believe that certain rules regarding variables make it a lot easier for the compiler to make as many optimisations as possible.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites
Ah I misinterpreted you.

OK, then use C++. Just sit down and start coding, you''re not responsible to anyone.

Share this post


Link to post
Share on other sites

  • Advertisement