Benchmarking different implementations of arrays
Code: "cpu_addtolist.py"
Programming language: Python
DMelt Version 1.4. Last modified: 02/04/1971. License: Free
http://jwork.org/dmelt/code/cache/cpu_addtolist_8425.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


from java.util import *
from jhplot import *
import time

a=P0D("high-performance")
b=ArrayList()
c=[]
r=Random()

Ntot=3000000 # number of events for testing

start = time.clock()
for i in range(Ntot):
      x=r.nextGaussian()
      a.add(x)
print ' CPU time for P0D (s) in Jython Loop=',time.clock()-start


start = time.clock()
a.randomNormal(Ntot, 0, 1)
print ' CPU time for P0D (s) native method =',time.clock()-start


start = time.clock()
for i in range(Ntot):
      x=r.nextGaussian()
      c.append(x)
print ' CPU time for Jython list (s)=',time.clock()-start



start = time.clock()
for i in range(Ntot):
      x=r.nextGaussian()
      b.add(x)
print ' CPU time for Java ArrayList (s)=',time.clock()-start