Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -


Posted by , 13 October 2005 · 230 views

Yeah I change my mind a lot.

After evaluating Rhino, I came to this conclusion: really no scripting language has a very fluid way of passing Java objects to a script.

So with that knowledge in hand, I went back to JRuby because a) I have a crush on that language, and b) I do know a roundabout way to pass a java object to a ruby script (just use the BSF).

So I set up a performance test. On one side is this ruby code:

include_class 'SVGSprite'

def draw
num_steps = 70;

for step in 0...num_steps
angle = step * 1.0 / num_steps * 2 * 3.1415926545;
loc_x = 100+ 40*Math.cos(angle);
loc_y = 100+ 30*Math.sin(angle);
$sprite.setRotation(angle + 3.1415926545/2);
$sprite.setPreferedSize(2, 15);
$g.draw($sprite, loc_x, loc_y, SVGSprite::CENTER);

public :draw

and the other side is the java version:

int num_steps = 70;
for (int step=0; step < num_steps; step++)
double angle = (float) step / num_steps * 2 * Math.PI;
double loc_x = 100+ 40*Math.cos(angle);
double loc_y = 100+ 30*Math.sin(angle);
sprite.setRotation(angle + Math.PI/2);
sprite.setPreferedSize(2, 15);
sprite.draw(g, (int)loc_x, (int)loc_y, SVGSprite.CENTER);

And the result is that the Java version worked 4 times faster than the JRuby version. That's ridiculous! The bulk of the processing time *should* be in the SVG rendering and the actual image drawing (the details of which are handled in java code), but somehow JRuby manages to take forever doing its thing. So that's it, that's the nail in the coffin, I'm done with it I promise.

So I think I'm going with BeanShell like H_o_p_s suggests. The nice thing is BeanShell looks a lot like Java, so if I ever get worried about performance, I can just copy-paste BeanShell code into java.

Also, while I had JRuby working, I did get to enjoy a few moments of interactive development (that is, changing the code while the game is running, and seeing the results right away). And let me tell you, it was delightful.

December 2016 »

456789 10

Recent Entries

Recent Comments

Recent Entries

Recent Comments