C++ performance myths debunked

Isaac To kkto at csis.hku.hk
Sat Aug 3 06:45:19 CEST 2002

>>>>> "Gerson" == Gerson Kurz <gerson.kurz at t-online.de> writes:

    Gerson> import win32api

    Gerson> def test(): s0 = win32api.GetTickCount() i = 0 while i < 100000:
    Gerson> for token in "This is, a test".split(): shit = token i += 1
    Gerson> elapsed = win32api.GetTickCount() - s0 print "Took %.2f" %
    Gerson> elapsed

    Gerson> Took 484 ms.

This is about the most stupid "debunk" to C++ efficiency.  You use the place
where Python give you the most performance, a module written completely in C
(the split method).  And then you compare it against the place where C++
give you the worst performance, namely a deep template written in a way to
give easy correctness rather than good performance (boost).  And now you
claim that C++ is no better than Python.

The core of the above code runs in C efficiency, not Python efficiency.  It
compares C vs. C++, which is more or less pointless (everybody know which is
faster).  The Python inefficiency comes only when long computations are in
the script.  If you instead home-brew your own implementation of split in
Python, you can honestly say you're comparing Python with C++.


More information about the Python-list mailing list