python vs perl performance test

igor.tatarinov at gmail.com igor.tatarinov at gmail.com
Thu Dec 13 17:53:03 EST 2007


On Dec 13, 1:23 pm, Jakub Stolarski <jakub.stolar... at gmail.com> wrote:
> If all you need is the result here's simpler and more efficient code:
>
> from random import randrange
> sum = 100 * randrange(128)
> print "Sum is ", sum
>
> And the same in perl:
>
> my $sum = 100 * int(rand(128));
> print "Sum is $sum\n";
>
> If you really want compare performance then look at Computer Language
> Benchmarks Game:http://shootout.alioth.debian.org/gp4/benchmark.php?test=all〈=pyt...

Sorry, this wasn't meant to be a benchmark of any kind and I don't
care about the results of the program. It was just an exercise to
figure out why the verbatim translation was so slow. It looks like
Python's randrange() is very slow. random() is much faster but then I
have to use int(N*random()) to get an integer, which is pretty slow
too.

Initially, I thought the difference was due to Python's slicing
implementation that doesn't seem to be the case: with fixed arguments
Perl's substr() and Python's slicing seem to have identical
performance.



More information about the Python-list mailing list