Surprising (for me) benchmark results...
E. Mark Ping
emarkp at CSUA.Berkeley.EDU
Tue May 1 18:33:10 EDT 2001
In article <m3y9sg90al.fsf at atrus.jesus.cam.ac.uk>,
Michael Hudson <mwh21 at cam.ac.uk> wrote:
>emarkp at CSUA.Berkeley.EDU (E. Mark Ping) writes:
>
>[python beats c++, java, perl in micro-benchmark]
>> import time
>>
>> start = time.time()
>> f = open("infile.txt", 'r')
>> out = open("outfile.txt", 'w')
>> l = f.readlines()
>> 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? 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.
>> out.writelines(l)
>> f.close()
>> out.close()
>> end = time.time()
>>
>> print (end-start), " seconds"
>
>Still, a nice result.
Indeed.
--
Mark Ping
emarkp at soda.CSUA.Berkeley.EDU
More information about the Python-list
mailing list