Javascript speed trials.

This file executes several speed tests for javascript statements. In order to get good measurement resolution, the tests are executed in loops of increasing size. The basic timer being used (via the Date object) has greater than 1 ms resolution, so we need to execute about 1000 iterations to get near 1 us (micro-second) resolution.

The first test is a calibration test of an empty javascript statement. The resulting time is subtracted from the subsequent tests to isolate the cost of the statements being executed (subtracting away the overhead of the test harness).



February 16, 2006

The following tests show a factor from 6 to 40 times better performance in IE6 when using the StBuf class instead of a generic string variable for concatenating 100's of strings (on my machine, concatenating 4,000 strings takes nearly 5 seconds in IE6, whereas the StBuf takes about 0.1 seconds!).

On Firefox, the built-in String concatenation operator is faster than the StBuf class - but not by much. In fact, for very large numbers of strings (100,000's), the StBuf class and String perform about the same.

function StBuf()
{
    this.rgst = new Array;
}
 
StBuf.prototype.Append = function(st)
{
    this.rgst.push(st);
}
 
StBuf.prototype.toString = function()
{
    return this.rgst.join("");
}

- Mike Koss