views:

102

answers:

1

I was wondering, if there is any generalities (among all the javascript engines out there) in the cost related to execute a given instruction vs another.

For instance, eval() is slower than calling a function that already has been declared.

I would like to get a table with several instructions/function calls vs an absolute cost, maybe a cost per engine.

Does such a document exists?

+2  A: 

There's a page here (by one of our illustrious hosts, no less) that gives a breakdown by browser and by general class of instruction:

http://www.codinghorror.com/blog/archives/001023.html

The above page links to a more detailed breakdown here:

http://www.codinghorror.com/blog/files/sunspider-09-benchmark-results.txt

Neither of those pages breaks down performance to the level of individual function calls or arithmetic operations or what have you. Still, there is quite a bit of potentially useful information.

There is also a link to the benchmark itself:

http://www2.webkit.org/perf/sunspider-0.9/sunspider.html

By viewing the benchmark source you can get a better idea of what specific function calls are being tested.

It also seems like it might be a simple matter to create your own custom version of the benchmark that collects the more specific data you are interested in. You could then run the modified benchmark on a variety of browsers, perhaps even taking advantage of a service such as browsershots.org to test a wide spectrum of browsers. Not sure how well that would work, but it might be fun to try....

It is of course possible that the same operation executed in the same browser might take significantly different amounts of time depending on the context in which it's being used, in ways that might not be immediately obvious. For example, I could imagine a Javascript engine spending more time optimizing code that is executed frequently, with the result that the code executed in a tight loop might run faster than identical code executed infrequently. Of course, that might not matter much in practice. Still, I imagine that a good table of the sort you are looking for might also summarize any such effects if they turned out to be important.

zaphod