A quick test with Python 3.2.3 and numpy int arrays yields (I also tested 
2.7.x and the results weren't much different):

arrayTest with n=1.0e+03 completed in 0.14937710762023926 seconds
arrayTest with n=1.0e+04 completed in 1.50266695022583 seconds
arrayTest with n=1.0e+05 completed in 14.913049936294556 seconds

These results are extremely slow. Well outside the ballpark of the 
Java/Scala/C# numbers. I tried PyPy, but that gave me errors with NumPy.

While Java is very strict about all libraries being native Java and fully 
JVM and cross platform, Python is not. Many Python libraries are written in 
C, particularly performance sensitive ones, so Python apps often run quite 
fast, even if they rely heavily on C code.

Python is popular because it's very simple, easy to learn, lightweight. 
It's easy to use without an IDE or project files or build scripts and it's 
frequently used through a REPL. None of these things are unique, 
Scala/Groovy come with excellent REPL interfaces, but I think Python gained 
a lot of mindshare for this type of usage. The big strength of Python is 
its community. Also, lots of people who previously would have used Matlab, 
R, or Mathematica for REPL centric calculation tasks (including myself) 
have switched to Python. Take a look at the SciPy conference and you can 
really see that there is a vibrant community of natural science types that 
have built up around Python.

Here is the Python code I used:

import numpy
import time

def arrayTest(n):
a = numpy.zeros(n, dtype=numpy.int)

# Do something with the array...
for i in range(0, n):
a[i] = i
for k in range(0, 100):
for i in range(0, n):
a[i] = a[n-1-i] * 2;

def doTiming(name, f):
start = time.time()
f()
elapsed = time.time() - start;
print('{0} completed in {1} seconds'.format(name, elapsed))

def timeArrayTest(n):
doTiming('arrayTest with n={0:.1e}'.format(n), lambda: arrayTest(n))

if __name__ == '__main__':
    timeArrayTest(1000)
    timeArrayTest(10000)
    timeArrayTest(100000)

-- 
You received this message because you are subscribed to the Google Groups "Java 
Posse" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/javaposse/-/tHYR3I6QqPYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to