ネタ01
kozawa さんが言ってた == 0 のが速いんじゃね話.
#!/usr/bin/js function bench(label, f) { var j; var t; t = (new Date).getTime (); j = f(); print(label + " " + ((new Date).getTime () - t) + "ms/" + j + " times"); } bench("++<Max ", function () {var j = 0;for (var i = 0; i < 1000000; i += 1) { j += 1; } return j}); bench("-->Max ", function () {var j = 0;for (var i = 0; i > -1000000; i -= 1) { j += 1; } return j}); bench("++<Zero", function () {var j = 0;for (var i = -1000000; i < 0; i += 1) { j += 1; } return j}); bench("-->Zero", function () {var j = 0;for (var i = 1000000; i > 0; i -= 1) { j += 1; } return j}); bench("--=Zero", function () {var j = 0;for (var i = 1000000; i != 0; i -= 1) { j += 1; } return j});
$ bench01.js ++<Max 516ms/1000000 times -->Max 487ms/1000000 times ++<Zero 505ms/1000000 times -->Zero 424ms/1000000 times --=Zero 445ms/1000000 times
なんかよくわからんくなってきた.
デクリメントが早いんですかね?