Scripting on Java and .NET Compared
|
|
20030407144812
If the Everything Coosely Coupled Architecture is the wave of the future, then Scripting would be an extremely important feature. I've previously blogged about the inadequacies of M******* VM with running dynamic typed languages. However how well will it do interpreting a scripting language?
I picked up the benchmark from this javaworld article, and ran it using the respective Javascript implementations. Here's the code:
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...");
allocArray(bench);
var end = new Date().getTime();
print( end - start );
start = new Date().getTime();
print("allocating and initializing a " + bench + "x" + bench + " element matrix...");
allocMatrix(500);
end = new Date().getTime();
print( end - start );
start = new Date().getTime();
bench = 1000000;
print("comparing an int against " + bench + " others...");
compare (bench, bench - 1);
end = new Date().getTime();
print( end - start );
Here are the results:
H:\\java\\scripting\\Rhino>java -jar js.jar -f countnet.js allocating and initializing a 1000000 element array... 3532 allocating and initializing a 1000000x1000000 element matrix... 187 comparing an int against 1000000 others... found = 999999 297 H:\\java\\scripting\\Rhino>jsc countnet.js M******* JS****t .*** Compiler version 7.00.9466 H:\\java\\scripting\\Rhino>countnet allocating and initializing a 1000000 element array... 10157 allocating and initializing a 1000000x1000000 element matrix... 1485 comparing an int against 1000000 others... found = 999999 906
Okay, so running Javascript using the Java VM is at least 3 times faster than the competition. No surprise here, furthermore, Rhino compiles source on the fly and doesn't leak unlike the competitor.

