Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Fast scripting...  (Read 2161 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 49
Projects: 5


I always win!


« Posted 2009-11-15 03:24:00 »

I'm looking into scripting for my game.

I've taken a look at Java's javax.script.* package, and it just sucks in regards of speed. I've also taken a look at Groovy, and it's better, runs fast with few objects (100'ish) but not fast enough with 500+.

Here's an example of 500 images being rotated:

1. Java's javax.script package/Rhino: under 10 fps.

2. Groovy: 90 fps.

3. Just plain old Java: 480 fps.


I know scripting isn't as fast, but I wasn't expecting this.

What am I doing wrong?


Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 9


Age of Conquest makes your day!


« Reply #1 - Posted 2009-11-15 04:00:46 »

How about Pnuts?

Offline Nate

JGO Kernel


Medals: 129
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #2 - Posted 2009-11-15 04:43:48 »

I'd be interested to see how Pnuts performs for you in relation to the others. Make sure the scripts are being compiled and not interpreted. Setting up your context like this should work:

1  
2  
3  
4  
Context context = new Context();
//context.setVerbose(true);
context.setImplementation(new CachedPnutsImpl());
context.setWriter(new PrintWriter(System.out, true));

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CommanderKeith
« Reply #3 - Posted 2009-11-15 05:07:48 »

Use janino, it's a scripting language which compiles the script to JVM bytecode so it's just as fast as java  Cool

Offline appel

JGO Wizard


Medals: 49
Projects: 5


I always win!


« Reply #4 - Posted 2009-11-15 05:37:21 »

How about Pnuts?

Refactored how I do things. instead of creating a new script for each object I only use one but reset the bindings between objects. Here's the results between Groovy and Pnuts:

@500 rotating objects:
- Groovy: 240-340 fps
- Pnuts: 240-340 fps
- Java: 360-500 fps

(The framerate seems to change between runs)

However, when I increase to 1000 rotating objects:

@1000 rotating objects:
- Groovie: 60-120 fps
- Pnuts: 120-130 fps
- Java: 270-280 fps


Groovie seems to be more memory intensive than Pnuts, I notice it takes a bit longer to start with.


Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Nate

JGO Kernel


Medals: 129
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #5 - Posted 2009-11-15 07:56:00 »

Yay! Glad to see Pnuts win. Cheesy

FWIW, CachedPnutsImpl compiles and caches scripts (using WeakHashMap) for reuse when you call load(script, context). Avoiding loading the script each time is much better though. If you don't need CachedPnutsImpl you should use context.setImplementation(new CompilerPnutsImpl()); to have scripts compiled to bytecode. If you don't call setImplementation then it will use PnutsImpl, which is a pure interpreter.

Groovy is quite a mess of a language. I personally would rather not have such wildly different syntax. Weird that its performance varied so much.

Use janino, it's a scripting language which compiles the script to JVM bytecode so it's just as fast as java  Cool
Many JVM languages can be compiled to bytecode. They are generally still slower though, as they are usually doing more per line of code to support fancy language features.

Offline CommanderKeith
« Reply #6 - Posted 2009-11-15 08:04:16 »

Many JVM languages can be compiled to bytecode. They are generally still slower though, as they are usually doing more per line of code to support fancy language features.

Yeah I don't know why all the scripting languages deviate from the java syntax so much. That's why janino's so cool, it uses the exact java syntax. The only downside is that it doesn't support generics or var-args yet. But janino is as quick as java (once you 'cook' it in the compiler).

Offline princec

JGO Kernel


Medals: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #7 - Posted 2009-11-15 12:24:21 »

What about JavaFX?

Cas Smiley

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #8 - Posted 2009-11-21 19:07:47 »

The thing with Janino is... it isn't really a scripting language. It's a very fast on-the-fly Java compiler. That's why you get the usual Java speed.

弾幕 ☆ @mahonnaiseblog
Offline zingbat

Senior Member




Java games rock!


« Reply #9 - Posted 2009-11-21 22:45:43 »

It means it's a better solution than using a scripting language.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2009-11-22 12:37:51 »

I dunno, I thought one of the benefits of scripting was to be free of the shackles of up front design... y'know, like ditching type declarations, the addition of top level functions, sensible overloading of the == operator, and nifty direct syntax for various types of collection...?

Cas Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (51 views)
2014-04-15 18:08:23

BurntPizza (47 views)
2014-04-15 03:46:01

UprightPath (63 views)
2014-04-14 17:39:50

UprightPath (45 views)
2014-04-14 17:35:47

Porlus (62 views)
2014-04-14 15:48:38

tom_mai78101 (86 views)
2014-04-10 04:04:31

BurntPizza (144 views)
2014-04-08 23:06:04

tom_mai78101 (243 views)
2014-04-05 13:34:39

trollwarrior1 (202 views)
2014-04-04 12:06:45

CJLetsGame (209 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!