Could Python supplant Java?
Daniel Berlin
dberlin at dberlin.org
Thu Aug 22 01:26:25 EDT 2002
> > 3. Tell me how even this small example program could be made 10X better
> > than it's C++ equivalant:
> >
> > http://www.cascade-sys.com/~jb/Pythonetics//glob/
>
> 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):
self.data [i] += p2.data[i]
which is going to make an awful lot of call overhead given the dimensions.
you'd simply write
self.data = add(self.data,p2.data)
Which makes one function call.
and dist2 would be rewritten something like:
return Numeric.sum (Numeric.power (Numeric.subtract (self.data, p2.data) , 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:
Starting....
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