Basic Swap vs math swap

JavaScript performance comparison

Test case created

Preparation code

Benchmark.prototype.setup = function() {
    var a = 2;
    var b = 4;

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Normal Swap
var c = a;
a = b;
b = c;
Math Swap
a += b;
b = a - b;
a -= b;

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers


Comment form temporarily disabled.

Add a comment