Serverside Javascript Tracemonkey Performance – Part IV

Path: mv.asterisco.pt!mvalente
From: mvale…@ruido-visual.pt (Mario Valente)
Newsgroups: mv
Subject: Serverside Javascript Tracemonkey Performance – Part IV
Date: Mon, 25 Aug 08 02:06:21 GMT

Before starting in on the Dromaeo and Sunspider tests, I decided
to run some tests to compare JS1.8tracemonkey with other languages.

For C, I created a couple of tests similar to Mike Shaver’s simple loop
but using instead the loop-sum and the function-sum tests from Sunspider
ubench tests.

http://shaver.off.net/diary/2008/08/22/the-birth-of-a-faster-monkey/

As you can see from the output below, JS1.8tracemonkey only comes close
to unoptimized gcc in a simple for loop. If the loop contains some
statements, as is the case, Tracemonkey is slower 2x/3x than compiled C.

To compare with other languages, I also created a direct copy of Tim Bray’s
Ruby code for his Wide Finder project, but with dismal results. My script clocks
in at nearly 5 secs using his o10k.ap 2Mb file sample (which would mean >500secs
with the o1000k.ap 200Mb file).

http://www.tbray.org/ongoing/When/200x/2007/09/20/Wide-Finder
http://mvalente.eu/Projects/wf1.js

It seems that the only language missing an entry in the Wide Finder challenge
is Javascript. I believe that the only reason for that is that people
just arent used to use Javascript to perform these type of tasks, due to the
misconception that “its for the browser and you cant access files”. I’m
curious to find out if with JS1.8tracemonkey we can get similar performance
to the other languages/contestants…

Tomorrow I hope to try and reproduce Santiago Gala’s and Fredrik Lundh
techniques and have a script that is more in line with the general results
for other languagues (meaning a ballpark 5-8 seconds for the 200Mb sample
or 50-80ms for the 2Mb sample). Or someone more versed in generators,
iterators, map/reduce and all that shiny new stuff might be kind enough
to send in the script :-)…

http://effbot.org/zone/wide-finder.htm
http://www.tbray.org/ongoing/When/200x/2007/10/30/WF-Results

—————————————-

[root@localhost perfjsvsc]# cat loop-sum.js; js18 -j loop-sum.js; time -p js18 -j loop-sum.js
var count = 99999999;
var sum = 0;
for (var i = 0; i < count; i++) {
sum = i + count;
}

real 0.84
user 0.19
sys 0.00

—-

[root@localhost perfjsvsc]# cat loop-sum.c; gcc -o loop-sum loop-sum.c; ./loop-sum; time -p ./loop-sum
int count = 99999999;
int i, sum = 0;

main()
{
for (i = 0; i < count; i++)
{
sum = i + count;
}
}
real 0.39
user 0.09
sys 0.00

—-

[root@localhost perfjsvsc]# cat function-sum.js; js18 -j function-sum.js; time -p js18 -j function-sum.js
function f(x, y, z)
{
return x + y + z;
}

for (var i = 0; i < 99999999; ++i)
f(1, 2, 3);

real 1.76
user 0.41
sys 0.00

—-

[root@localhost perfjsvsc]# cat function-sum.c; gcc -o function-sum function-sum.c; ./function-sum; time -p ./function-sum
int f(int x, int y, int z)
{
return x + y + z;
}

main()
{
int i;

for (i = 0; i < 99999999; ++i)
f(1, 2, 3);
}

real 0.69
user 0.17
sys 0.00

—————————————-

— MV

Comments are closed.