You are a guest. Restricted access. Read more.
Command disabled: backlink
SCaVis manual

Using Jython/Python

Benchmarking Jython

Here you can find some benchmark results for Jython and BeanShell scripting. See Other languages Section

As explained in Section running_scripts, one can execute macros/source files using the “run” button: SCaVis recognizes file formats on the fly. Read also online resources in Sect.Jython,BeanShell and Java resources.

Here is an example which benchmarks several arrays implemented in the native Java (ArrayList), Python (list) and SCaVis P0D array. The script below checks the CPU time needed to fill these arrays with Gaussian-distributed random numbers:

Code example

  Download for this example is disabled for non-members
 1: from java.util import *
 2: from jhplot import *
 3: import time
 4:
 5: a=P0D("high-performance")
 6: b=ArrayList()
 7: c=[]
 8: r=Random()
 9:
10: Ntot=3000000 # number of events for testing
11:
12: start = time.clock()
13: for i in range(Ntot):
14:       x=r.nextGaussian()
15:       a.add(x)
16: print ' CPU time for P0D (s) in Jython Loop=',time.clock()-start
17:
18:
19: start = time.clock()
20: a.randomNormal(Ntot, 0, 1)
21: print ' CPU time for P0D (s) native method =',time.clock()-start
22:
23:
24: start = time.clock()
25: for i in range(Ntot):
26:       x=r.nextGaussian()
27:       c.append(x)
28: print ' CPU time for Jython list (s)=',time.clock()-start
29:
30:
31:
32: start = time.clock()
33: for i in range(Ntot):
34:       x=r.nextGaussian()
35:       b.add(x)
36: print ' CPU time for Java ArrayList (s)=',time.clock()-start

A typical result (using G2030, Dell Insperon 660s) of this benchmark is shown below:

 CPU time for P0D (s) in Jython Loop= 2.792909833
 CPU time for P0D (s) native method = 0.390237158
 CPU time for Jython list (s)= 2.443057156
 CPU time for Java ArrayList (s)= 3.608499232

As you can see, the performance of P0D when using its native method is a factor 10 better.

To speed up your applications, use the native methods of the SCaVis classes when possible

Benchmarking BeanShell

You can also use the BeanShell as an alternative scripting language. Generally, BeanShell is slower the Jython in loops, but if you call the native methods of high-performance classes (as for P0D in the example above), then the execution speed will be very similar:

import java.util.*;
import jhplot.*;
import time.*;
 
a=new P0D("high-performance");
b=new ArrayList();
r=new Random();
 
Ntot=3000000; //  number of events for testing
 
start= System.currentTimeMillis();
for (i=0; i<Ntot; i++){
      x=r.nextGaussian();
      a.add(x);
      };
 
print("CPU time for P0D (s) in Jython Loop=");
print(0.001*(System.currentTimeMillis()-start));
 
start= System.currentTimeMillis();
a.randomNormal(Ntot, 0, 1);
print("CPU time for P0D (s) native  Loop=");
print(0.001*(System.currentTimeMillis()-start));
 
 
start= System.currentTimeMillis();
for (i=0; i<Ntot; i++){
      x=r.nextGaussian();
      b.add(x);
      };
 
print("CPU time for Java ArrayList Loop=");
print(0.001*(System.currentTimeMillis()-start));

Running the above code in the SCaVis gives:

bsh %
CPU time for P0D (s) in Jython Loop= 7.118
CPU time for P0D (s) native  Loop=0.377
CPU time for Java ArrayList Loop=7.131

BeanShell is a factor two slower then Jython in loops, but the performance is very similar to Jython when calling the native Java-implemented methods

You are not full member and have a limited access to this section. One can unlock advanced pages after becoming a full member. You can also request to edit this manual and insert comments.

Benchmarking Groovy

You can also use Groovy as an alternative scripting language.

import jhplot.P0D 
 
a=new P0D("high-performance")
r=new java.util.Random()
 
Ntot=3000000 
start=System.currentTimeMillis();
for (i=0; i<Ntot; i++){
      x=r.nextGaussian()
      a.add(x)
}
end_time=System.currentTimeMillis();
println  (end_time-start)/1000

The output printed in JRubyShell is

   0.8

(0.8 seconds with a spread of 0.1)

Benchmarking JRuby

You can also use JRuby as an alternative scripting language.

include_class Java::jhplot.P0D
 
a=P0D.new("high-performance")
r=java.util.Random.new()
 
Ntot=3000000 # number of events for testing
start=Time.now
for i in 1..Ntot
      x=r.nextGaussian()
      a.add(x)
end
 
end_time= Time.now
puts "Time elapsed #{(end_time - start)} seconds"

The output printed is

  Time elapsed 0.8 seconds

The conclusion: loops in Goovy and JRuby are faster than in Jython by 20 percent, and much faster than in BeanShell

click here if you want to know more

click here if you want to know more

click here if you want to know more

A complete description of how to use Jython for scientific analysis is described in the book Scientific data analysis using Jython and Java published by Springer Verlag, London, 2010 (by S.V.Chekanov)

Sergei Chekanov 2011/07/02 19:52

man/program/jython.txt · Last modified: 2013/08/04 18:31 by admin
CC Attribution-Share Alike 3.0 Unported
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5