Skip to content.

Manageability

Sections
Personal tools
You are here: Home » blog » archive » The Leaky JScript.NET Compiler
Views
  • State: published

The Leaky JScript.NET Compiler

Document Actions
20030408104305

How well does Microsoft's JScript .NET compiler work with a script that is truly dynamic?  I rewrote my earlier benchmark to a form that couldn't be pre-compiled.  Here's the code:

var fstmt = "function allocMatrix(howmany) {" + 

" var intArray = new Array(howmany);" + 

" for (var i = 1; i <= howmany; i++) {" + 

" var intArray2 = new Array(howmany);" + 

" intArray[i] = intArray2;" + 

" for (var j = 1; j <= howmany; j++) {" + 

" intArray2[j] = i;" + 

" }" + 

" }" + 

"}" + 

"function allocArray(howmany) {" + 

" var intArray = new Array(howmany);" + 

" for (var i = 1; i <= howmany; i++) {" + 

" intArray[i] = i;" + 

" }" + 

"}" + 

"function compare(howmany, value) {" + 

" for (var i = 0; i <= howmany; i++) {" + 

" if (i == value) {" + 

" print('found=' + i);" + 

" } " + 

" }" + 

"}"; 



var bench = 1000000;

var start = new Date().getTime();

print("allocating and initializing a " + bench + " element array...");

eval(fstmt + "allocArray(1000000)");

var end = new Date().getTime();

print( end - start );

start = new Date().getTime();

print("allocating and initializing a " + bench + "x" + bench + " element matrix...");

eval(fstmt + "allocMatrix(500)");

end = new Date().getTime();

print( end - start );

start = new Date().getTime();

bench = 1000000;

print("comparing an int against " + bench + " others...");

eval(fstmt + "compare (1000000, 1000000 - 1)");

end = new Date().getTime();

print( end - start );

start = new Date().getTime();

for(var i =0; i< 15000; i++)

{

eval( fstmt + "bench+" + i + ";");

}

print( "survived!" );

end = new Date().getTime();

print( end - start );



Here's are the results:


>java -jar js.jar -f evaltest.js

allocating and initializing a 1000000 element array...

4391

allocating and initializing a 1000000x1000000 element matrix...

454

comparing an int against 1000000 others...

found=999999

828

survived!

11220

>jsc /fast- evaltest.js

>evaltest

allocating and initializing a 1000000 element array...

15752

allocating and initializing a 1000000x1000000 element matrix...

4813

comparing an int against 1000000 others...

found=999999

3626

survived!

92620

First of all, you have to use the "/fast" flag otherwise the compiled code will crash.  Second, if you compared the execution times, you'll notice that the performance difference gets wider.  Finally, for the case where I dynamically compile a snippet 15,000 times, Rhino is over 8 times faster, but what's truly remarkable is that the memory consumption remains contained while for JScript it explodes to over 400Mbytes!


Last modified 2003-07-30 04:16 PM
 

Powered by Plone

This site conforms to the following standards: