Swap variables (v9)

Revision 9 of this benchmark created on


Description

Tests the quickest way to swap the values of two variables without using a temporary variable (with the temporary variable method for reference).

Setup

var a = 1, b = 2;

Test runner

Ready to run.

Testing in
TestOps/sec
Array 'hack'
b = [a, a = b][0];
ready
Bitwise operators
a = a ^ b;
b = a ^ b;
a = a ^ b;
ready
Temporary variable
var c = a;

a = b;
b = c;
ready
destructuration
[b , a] = [a, b];
ready

Revisions

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