Last question of the day (This one's easy!)

Gordon McMillan gmcm at hypernet.com
Thu Sep 30 21:51:20 EDT 1999


[Nolan Darilek thinking of writing a MUD server]

> Now, however, I'm becoming concerned about how possible/practical
> this would be, and if I'm possibly using Python for something for
> which it isn't intended. I began doing research into Python's
> speed vs. Java, and had some concerns.

[concerned by Roger's benchmark from his '96 Java paper, 
which measures function call overhead]

> Running the compiled Java code produces the following on my PPro
> 200:
> 
> ethereal:~> java BenchMark
> Start Time: Thu Sep 30 17:53:00 CDT 1999
> End Time: Thu Sep 30 17:53:41 CDT 1999
> 
> So we see that it takes roughly 41 seconds to loop through
> 100000000 method calls. Not bad. I ran py_compile on the Python
> module though, and here's what I get:
> 
> ethereal:~> python test.pyc
> Thu Sep 30 17:56:53 1999
> 
> It is now almost 5:59, and the task is still running. So, it
> looks as if Python is much slower at this particular benchmark
> than Java.
> 
> My first question is, should I even care? 

No. Function call overhead in Python is fairly large, but very 
rarely of practical concern (unless you have an extreme 
functional coding style, in which case you'd be using a 
functional language anyway).

Look at it this way: in the time it takes you to get something 
working in Java, you'll be able to do 5 complete rewrites in 
Python. No, I'm not kidding. By the time you've done it 5 
times, you'll not only have it right, you'll have optimized your 
design, with far greater payback.

On Monday, I took some complex C code searching a bunch 
of peculiar in-memory data structures that the client had been 
futzing with for years. I imitated the data structures and 
search algorithm in Python. By the end of the day, I had a 
new algorithm (and altered structures) that ran 200x faster. By 
Wednesday, it was working in C. 

Now granted, these are not particularly clueful clients <hee 
haw>, but the point is that focusing on design and algorithms 
is a whole lot more effective than futzing with details.

And if you do need more speed, it is relatively easy to extend 
Python.

- Gordon




More information about the Python-list mailing list