Archive for August, 2006

Microsoft JScript -vs- GameMonkey

Wednesday, August 2nd, 2006

I’ve been working with the PopCap game development frmework. It’s pretty sweet but I would like to have some kind of scripting ability for tweaking various game parameters. JavaScript seems like the logical answer since I’m a big fan of it and have lots of experience integrating the engine into my apps.

I had heard about another scripting engine called GameMonkey. Its syntax is very close to JavaScript and seemed to be really fast based on running some of the demo scripts that come with the distribution.

I noticed that GameMonkey came with a benchmark script. Since it is so similar to JavaScript it only took me a few minutes to port the script over so that I could compare the speeds. WOW. GameMonkey is pretty fast as you’ll see by the test results below.

My good friend Neil is a serious JavaScript head. I think he has some benchmark tests I might be able to try as well. Something really string heavy I suspect ;)

Now, I’m not advocating GameMonkey over JScript/JavaScript. Nope. I don’t know enough about it to make any kind of judgment on its suitability for a project but based on its performance with this particular set of tests, I think I’m going to look into it a little further.

The Ackerman test tests the engine’s ability to manipulate the stack. The test is highly recursive. So much so that I had to reduce the depth a little because JScript would error out with an Out of Stack Space error. I modified it in both tests to be fair.

The Fibonacci test simply calculates the Fibonacci sequence up to 32.

The matrix test builds two 30 x 30 matricies and then multiplies each of them 300 times.

The hash test is a very simple hashtable test. It tests the speed of building up an associative array of 80000 elements, then tests all the values in the array.

The heapsort test again builds an array of 80000 but generates a random number for the value of each element. It then sorts the array via the heapsort algorithm implemented in script.

Test JScript GameMonkey
Akerman 1.703 sec 0.163 sec
Fibonacci 15.641 sec 1.431 sec
Matrix 19.813 sec 1.942 sec
Hash 1.843 sec 0.198 sec
Heapsort 1.313 sec 0.698 sec

Microsoft JScript

Microsoft JScript(CScript host):Microsoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

*** ACKERMAN ***1021time = 1703*** FIB ***3524578time = 15641*** MATRIX ***.....270165 1061760 1453695 1856025time = 19813*** HASH ***80000time = 1843*** HEAPSORT ***

time = 1313

GameMonkey:

*** ACKERMAN ***1021time = 0.162935*** FIB ***3524578time = 1.43161*** MATRIX ***270165 1061760 1453695 1856025time = 1.94145*** HASH ***13880time = 0.19747*** HEAPSORT ***0.989883time = 0.697939