Surprising (for me) benchmark results...

Michael Hudson mwh21 at cam.ac.uk
Tue May 1 18:41:18 EDT 2001


emarkp at CSUA.Berkeley.EDU (E. Mark Ping) writes:

> >> l.sort()
> >  ^ this line would be my bet for why Python wins.  What sort did you
> >use in the other languages?
> 
> In Perl and Java, the builtin sort, and in C++ std::sort.  Why would
> you expect this to be best in Python?  

'cause Tim Peters wrote the code that sorts lists in Python,
basically.

> I inserted timing for the sort, and in Python (in the small case) it
> was about 180 ms, whereas in C++ it was about 140 ms.

Fair enough.  I wonder where the speed is then?  Might be in creating
the list/vector before sorting?  The code in
Objects/fileobject.c:file_readlines seems quite clever, so that might
be it.  Is the C++ basically:

while (!file.eof()) {
    vector.push_back(if.get_line());
}

? (or whatever; I haven't used C++'s IO library for a loong time).  We
might be seeing the benefits of a higher level of abstraction here.

Cheers,
M.

-- 
  MARVIN:  What a depressingly stupid machine.
                    -- The Hitch-Hikers Guide to the Galaxy, Episode 7



More information about the Python-list mailing list