Performance question with bsh objects

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Performance question with bsh objects

bart.jourquin
Hi all,

It seems that the creation of new instances of objects that are defined in in a .bsh script is very slow, when compared to pure java code executed by the JVM.

In the following example (called from a java app, using Interpreter.source("test.bsh") , populating the HashMap  is very slow. Maybe I'm somewhere wrong?

Any help appreciated!

Bart

----------------------------------------
test.bsh
----------------------------------------
import java.utils.*;

class MyObject {
  private int value;

  public MyObject(int a) {
    value = a;
    }

  public int getValue() {
    return value;
    }
}

HashMap hm = new HashMap();
for (int i = 0 ; i < 100000 ; i++) {
  hm.put(new Integer(i), new MyObject(i));
  }


-- 
Prof Dr Bart Jourquin
F.U.Ca.M. - G.T.M.
Chaussée de Binche, 151a
B7000 Mons, Belgium
Tel. : +32 65 323293
Fax. : +32 65 315691
http://www.fucam.ac.be/jourquin

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Performance question with bsh objects

David Lee

Experts please correct me ...  This is the opinion of a "novice" BSH user ...
 
The issue with BeanShell is that its an interpreter, and its "Classes" are not exatly the same as java classes. 
Your BSH script is not pure compiled java code.
What looks like java code is represented with BSH's own class structure and interpret data structures.
Thus tight loops doing very native-java things in BSH are bound to be much slower then pure java.
How much ? My "guess" would be maybe 10x slower ?  For constructing BSH objects I'd guess more ...
maybe 20-30x ?  (Because BSH objects are not the same as Java objects ... even if they look like them in source)
Is that about what your seeing ?
 
Code that is BSH driving more expensive java code will show very little overhead compared to "pure java" doing the same thing.
That is if you have one statement in BSH that calls a java method that does 1000 statements, the overhead of BSH will be almost 0%.
Most usages fall somewhere in between...
 
I don't consider any of this 'bad' ... its what you get with an interpretive language ... The benefits do have some cost.
 
If you find the creation of objects too expensive for your use, you could expose a native java BSH "command" that constructs similar objects within java ... or pass in a java "factory" type class for construction.   Of course you will then be confined to only the features of native java classes and the code for that class wont be BSH code.
 
Now if someone would just write a C interpreter in BSH we'd be styling ! :)  (You could then compile the java source with it, and run BSH on top of that ... whoo hoo !!! Turtles all the way down ... )
 
 
-----------------------------------------------------------
David A. Lee
[hidden email] 
http://www.calldei.com
----- Original Message -----
Sent: Friday, November 10, 2006 6:59 AM
Subject: [Beanshell-users] Performance question with bsh objects

Hi all,

It seems that the creation of new instances of objects that are defined in in a .bsh script is very slow, when compared to pure java code executed by the JVM.

In the following example (called from a java app, using Interpreter.source("test.bsh") , populating the HashMap  is very slow. Maybe I'm somewhere wrong?

Any help appreciated!

Bart

----------------------------------------
test.bsh
----------------------------------------
import java.utils.*;

class MyObject {
  private int value;

  public MyObject(int a) {
    value = a;
    }

  public int getValue() {
    return value;
    }
}

HashMap hm = new HashMap();
for (int i = 0 ; i < 100000 ; i++) {
  hm.put(new Integer(i), new MyObject(i));
  }


-- 
Prof Dr Bart Jourquin
F.U.Ca.M. - G.T.M.
Chaussée de Binche, 151a
B7000 Mons, Belgium
Tel. : +32 65 323293
Fax. : +32 65 315691
http://www.fucam.ac.be/jourquin


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642


_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Performance question with bsh objects

bart.jourquin
David,

Thanks for your answer. Digging a little more in the bsh docs, I tried the following implementation, which seems to be much more efficient... but I don't understand very well why....

Bart

-----------------------------------
import java.utils.*;

MyObject(int a) {
  int value = a;
return this;
}

HashMap hm = new HashMap();
for (int i = 0 ; i < 100000 ; i++) {
  m = MyObject(i);

  hm.put(new Integer(i), m);
  }
------------------------




Le vendredi 10 novembre 2006 à 08:16 -0600, David A. Lee a écrit :

Experts please correct me ...  This is the opinion of a "novice" BSH user ...
 
The issue with BeanShell is that its an interpreter, and its "Classes" are not exatly the same as java classes. 
Your BSH script is not pure compiled java code.
What looks like java code is represented with BSH's own class structure and interpret data structures.
Thus tight loops doing very native-java things in BSH are bound to be much slower then pure java.
How much ? My "guess" would be maybe 10x slower ?  For constructing BSH objects I'd guess more ...
maybe 20-30x ?  (Because BSH objects are not the same as Java objects ... even if they look like them in source)
Is that about what your seeing ?
 
Code that is BSH driving more expensive java code will show very little overhead compared to "pure java" doing the same thing.
That is if you have one statement in BSH that calls a java method that does 1000 statements, the overhead of BSH will be almost 0%.
Most usages fall somewhere in between...
 
I don't consider any of this 'bad' ... its what you get with an interpretive language ... The benefits do have some cost.
 
If you find the creation of objects too expensive for your use, you could expose a native java BSH "command" that constructs similar objects within java ... or pass in a java "factory" type class for construction.   Of course you will then be confined to only the features of native java classes and the code for that class wont be BSH code.
 
Now if someone would just write a C interpreter in BSH we'd be styling ! :)  (You could then compile the java source with it, and run BSH on top of that ... whoo hoo !!! Turtles all the way down ... )
 
 
-----------------------------------------------------------
David A. Lee
[hidden email] 
http://www.calldei.com
----- Original Message -----
From: [hidden email]
To: [hidden email]
Sent: Friday, November 10, 2006 6:59 AM
Subject: [Beanshell-users] Performance question with bsh objects


Hi all,

It seems that the creation of new instances of objects that are defined in in a .bsh script is very slow, when compared to pure java code executed by the JVM.

In the following example (called from a java app, using Interpreter.source("test.bsh") , populating the HashMap  is very slow. Maybe I'm somewhere wrong?

Any help appreciated!

Bart

----------------------------------------
test.bsh
----------------------------------------
import java.utils.*;

class MyObject {
  private int value;

  public MyObject(int a) {
    value = a;
    }

  public int getValue() {
    return value;
    }
}

HashMap hm = new HashMap();
for (int i = 0 ; i < 100000 ; i++) {
  hm.put(new Integer(i), new MyObject(i));
  }


-- 
Prof Dr Bart Jourquin
F.U.Ca.M. - G.T.M.
Chaussée de Binche, 151a
B7000 Mons, Belgium
Tel. : +32 65 323293
Fax. : +32 65 315691
http://www.fucam.ac.be/jourquin




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
-- 
Prof Dr Bart Jourquin
F.U.Ca.M. - G.T.M.
Chaussée de Binche, 151a
B7000 Mons, Belgium
Tel. : +32 65 323293
Fax. : +32 65 315691
http://www.fucam.ac.be/jourquin

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users