Hi All.

Following code take some measurements.

In first part I take time between invocation method Timer.print() from code as usual.

In second part, the same method invoke from Beanshell interpreter.

 

import bsh.*;

public class Test2 {

 

public static void main(String[] args){

try{

int iterationCount = 5;

for (int i = 0; i < iterationCount; i++){

Timer.getTimer().print("1");

Timer.getTimer().print("2");

Timer.getTimer().print("3");

}

System.out.println("");

Interpreter newInterpret = new Interpreter();

newInterpret.setStrictJava(false);

newInterpret.eval("import Test2.Timer;");

String _body1 = "Timer.getTimer().print(\"from bsh 1\");Timer.getTimer().print(\"from bsh 2\");Timer.getTimer().print(\"from bsh 3\");";

newInterpret.eval(_body1);

for (int i = 0; i < iterationCount; i++){

newInterpret.eval(_body1);

}

}

catch (EvalError ex){

ex.printStackTrace();

}

}

public static class Timer{

long lastTime = System.nanoTime();

static Timer INSTANCE = new Timer();

public static Timer getTimer(){

return INSTANCE;

}

public void print(String str){

long newTime = System.nanoTime();

System.out.println(str+" : "+ (newTime-lastTime)+" nanosec.");

lastTime = newTime;

}

}

}

 

I have taken following result:

 

1 : 32515 nanosec.

2 : 719588 nanosec.

3 : 124228 nanosec.

1 : 94568 nanosec.

2 : 108539 nanosec.

3 : 90011 nanosec.

1 : 83388 nanosec.

2 : 85816 nanosec.

3 : 88165 nanosec.

1 : 86933 nanosec.

2 : 85784 nanosec.

3 : 85974 nanosec.

1 : 94706 nanosec.

2 : 87694 nanosec.

3 : 83348 nanosec.

from bsh 1 : 401021900 nanosec.

from bsh 2 : 1868599 nanosec.

from bsh 3 : 916432 nanosec.

from bsh 1 : 1218187 nanosec.

from bsh 2 : 822823 nanosec.

from bsh 3 : 782107 nanosec.

from bsh 1 : 1141407 nanosec.

from bsh 2 : 719088 nanosec.

from bsh 3 : 690071 nanosec.

from bsh 1 : 1077352 nanosec.

from bsh 2 : 719527 nanosec.

from bsh 3 : 719083 nanosec.

from bsh 1 : 1199250 nanosec.

from bsh 2 : 778980 nanosec.

from bsh 3 : 735542 nanosec.

from bsh 1 : 11945966 nanosec.

from bsh 2 : 1364494 nanosec.

from bsh 3 : 1792958 nanosec.

 

Is somebody explaining for me, why time of invocation from Beanshell on one order greater than time of code invocation?

And what can I do for decrease this time in Beanshell?

 

 

 

Hope for help, thanks in advance

 

Andrey

 

mailto:Andrey.Svirid@itc.by