swap variables in different ways (v12)

Revision 12 of this benchmark created by Ted Hopp on


Description

Various ways of swapping two values. Most test cases work for variables of any type; the "bit" method works only for integers.

Setup

var a = 1,
        b = 2;

Test runner

Ready to run.

Testing in
TestOps/sec
array
b = [a, a = b][0];
ready
variable
var c = a;

a = b;
b = c;
ready
bit
a = a ^ b;
b = a ^ b;
a = a ^ b;
ready
comma operator
b = a + (a=b, 0);
ready

Revisions

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