WHY is python slow?

Mitchell Morris mitchell.morris at cingular.com
Thu Jun 7 08:34:09 EDT 2001


Steven Haryanto <steven at haryan.to> wrote in <mailman.991900751.7603.python-
list at python.org>:

> Although it is generally accepted that Python is slower than
> Java/Perl/Ruby, a layman like me would be curious to know why
> exactly this is so. In other words, why is the implementation
> of a language like Ruby (which is on par with Python in terms
> of 'everything is an object', strong reflection, dynamic
> nature).
> 
> My first guess would be the ubiquitous use of dictionaries?
> 
> Steve
> http://stevne.haryan.to/
> 
> 

Well, perhaps your population sample isn't actually representative. I, for 
one, don't believe that your speed ordering is accurate, and I would 
further postulate that few other people on this newsgroup would agree with 
you.



My second observation is that constructing a group of languages that 
includes Java, Perl, and Ruby as members but doesn't include Python must be 
using a very fine discriminant indeed <wink>.



As a single point of data, may I present the language-specific pages from 
Bagley's "Computer Language Shootout" 
<URL:http://www.bagley.org/~doug/shootout/>. Each presents the finishing 
place for that language on each specific test. In addition, the average 
finishing place is calculated through an unspecified method (I'm assuming 
it's the arithmetic mean, but I'm not sure) in three categories: CPU usage, 
memory usage, and lines of code.
    	Perl:
    	    	CPU: 14, Memory: 17, LOC: 7
        	http://www.bagley.org/~doug/shootout/lang/perl/
    	Python:
    	    	CPU: 17, Memory: 12, LOC: 7
    	    	http://www.bagley.org/~doug/shootout/lang/python/
    	Ruby:
    	    	CPU: 18, Memory: 14, LOC: 5
    	    	http://www.bagley.org/~doug/shootout/lang/ruby/
    	Java:
    	    	CPU: 12, Memory: 20, LOC: 15
    	    	http://www.bagley.org/~doug/shootout/lang/java/
    	Tcl:
    	    	CPU: 19, Memory: 12, LOC: 12
    	    	http://www.bagley.org/~doug/shootout/lang/tcl/
    	OCaml: [my new favorite toy -- ed.]
    	    	CPU: 3, Memory: 5, LOC: 10
    	    	http://www.bagley.org/~doug/shootout/lang/ocaml/
Under this ranking, Java is barely faster than Perl which is even more 
barely faster than Python which just as barely faster than Ruby which is 
(once again) only barely faster than Tcl. Mr.Bagley neglected to provide 
summary statistics for inter-language comparisons on these pages, so I have 
to provide my own:

    	Language    	Mean    	Std.Dev
    	--------    	----    	-------
    	Perl    	    	13.6    	6.2
    	Python    	    	16.6    	3.8
    	Ruby    	    	18.0    	4.6
    	Java    	    	11.5    	4.2    
    	Tcl    	    	20.8    	4.0

(Warning: undocumented math and unwarranted jumping-to-conclusions ahead)

Notice the large standard deviation for Perl's results, especially compared 
to the standard deviation of the other datasets. This suggests that there 
are some outliers in the Perl dataset which are skewing the mean, and that 
generally the other languages perform more consistently over these tests. 
In addition, the mean/std.dev comparisons suggest that we can't yet 
conclude that Perl actually finshes ahead of either Python or Ruby in the 
general case, but they do suggest that we can tentatively say that Perl 
finshes ahead of Tcl for these tests. (Isn't it wonderful how statistics 
lets you be so certain about making such sweeping statements? <0.1 wink>)




I have my own reservations about the applicability of this shootout to 
anything but Usenet arguments, but since that *IS* what we're having I'm 
delighted to wield it <wink>.



if-you'd-only-claimed-Jython-was-slow-ly y'rs,
+Mitchell



P.S. Keep in mind that all this is based on the finishing placements in the 
elements of the test suite, not the raw performance numbers which I didn't 
feel like extracting from all over the entire website. Jiggery-pokery, 
indeed!



More information about the Python-list mailing list