Could Python supplant Java?

Daniel Berlin dberlin at
Thu Aug 22 07:26:25 CEST 2002

> > 3. Tell me how even this small example program could be made 10X better
> > than it's C++ equivalant:
> > 
> >
> What??? After all the talk of 100K+ programs you cite a 300 line 
> C++ program?? ;-)

And one written poorly, to boot.
Not algorithmically, but in that it obviously should be using 
numeric python, since it's completely compute intensive.
okay, not completely compute intensive, it is also call overhead 
intensive in the python version.
Numeric python would help that, actually, since rather than your

for i in xrange (self.dim): [i] +=[i]

which is going to make an awful lot of call overhead given the dimensions.
you'd simply write = add(,

Which makes one function call.
and dist2 would be rewritten something like:

                return Numeric.sum (Numeric.power (Numeric.subtract (, , 2))
(I'm doing this off the cuff).

It would be a *whole bunch* faster, too (orders of magnitude).

I should point out that I can't get the C++ version to work right on my 
Linux box, either with Intel's compiler, or g++ (after taking out the 
pointless stdafx.h include, etc).
I'm too lazy to debug it.
It always says:
MadeData in 0.17 sec.
Count: 307200, 0.18 sec.
Done in 0.35 sec, 0.52 overall, 2 iterations

No matter what.
Even if i seed the random number generator.

But anyway.

More information about the Python-list mailing list