Author: David Blackman
Date: 20:33:08 07/02/99
Go up one level in this thread
On July 02, 1999 at 15:07:33, Sven Reichard wrote: >In a recent thread it was stated that current Basic compilers produce code that >is "slightly faster than C (and a lot faster than C++)". >Could someone point out to me why C++ per se is slow? I had programmed in C for >a while before learning C++, and I didn't detect any significant differences in >performance. However, with C++ I spent more time designing and less time >debugging (which makes it preferable to me :) ). >I recently started implementing a generic engine for two person zero sum games >(in C++). I would like to know if it is worth the effort, or if the language >slows it down too much. > >Thanks, >Sven. If you are a good C++ programmer, or you are doing this project in the hope of getting better at C++, then go for it. There are a couple of reasons to do with aliasing why C and C++ should be a bit slower than other languages, but in practice this has only been significant on a few strange machines such as vector supercomputers. For most machines C and C++ will give code as good or better than anything else. In particular i'd be very surprised to see a Basic compiler do better than C or C++ for any significant sized CPU intensive program. As to the C vs C++ question, there shouldn't be a lot of difference. It is possible to write slow and bloated C++, but if you are sensible it is ok. Don't overuse virtuals (as Bruce pointed out), put objects on the stack where appropriate (instead of new everywhere) and have the really trivial access methods inline. Also be careful with templates and exceptions, especially if your compiler doesn't support them very well. With the Gnu compilers i find C++ code size noticeably bigger than C, but not much speed difference. This is for a compiler that is very mature for C, but quite new for C++. With more mature C++ compilers there should be even less difference. At the start i said "If you are a good C++ programmer" because the language is big, hard to learn, and often surprising. Once learnt, it is fairly satisfactory and has good performance.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.