Benchmarking different implementations of arrays
Source code name: "cpu_addtolist.py"
Programming language: Python
Topic: Data arrays/P0D
DMelt Version 1.4. Last modified: 11/08/2020. License: Free
https://datamelt.org/code/cache/cpu_addtolist_1312.py
To run this script using the DataMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


from java.util import Random
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