Created
August 12, 2011 00:28
-
-
Save uhop/1141172 to your computer and use it in GitHub Desktop.
Compare ++, --, +=, -=, = +, and = -, with different values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compare ++, --, +=, -=, = +, and = -, with different values. | |
var a = 1, p1 = 1, m1 = -1, p9 = 9, m9 = -9; | |
this.group( | |
"inc/dec by 1", | |
function baseline() { return a; }, | |
function prefix_plus_plus() { ++a; return a; }, | |
function postfix_plus_plus() { a++; return a; }, | |
function prefix_minus_minus() { --a; return a; }, | |
function postfix_minus_minus() { a--; return a; }, | |
function plus_eq() { a += 1; return a; }, | |
function minus_eq() { a -= -1; return a; }, | |
function eq_plus() { a = a + 1; return a; }, | |
function eq_minus() { a = a - (-1); return a; } | |
); | |
this.group( | |
"inc/dec by 1 (var)", | |
function plus_eq_v1() { a += p1; return a; }, | |
function minus_eq_v1() { a -= m1; return a; }, | |
function eq_plus_v1() { a = a + p1; return a; }, | |
function eq_minus_v1() { a = a - m1; return a; } | |
); | |
this.group( | |
"inc/dec by 9 (var)", | |
function plus_eq_v9() { a += p9; return a; }, | |
function minus_eq_v9() { a -= m9; return a; }, | |
function eq_plus_v9() { a = a + p9; return a; }, | |
function eq_minus_v9() { a = a - m9; return a; } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Benchmark it with http://www.perfjs.com/