diff --git a/bench/numbers.js b/bench/numbers.js index cdc741f..469436b 100644 --- a/bench/numbers.js +++ b/bench/numbers.js @@ -4,31 +4,34 @@ var benchmark = require('benchmark') var suite = new benchmark.Suite() function sum (base, max) { - var total = 0 - - for (var i = base; i < max; i++) { + var total = base + for (var i = base + 1; i < max; i++) { total += i } + return total } suite.add('sum small', function smallSum () { var base = 0 var max = 65535 + // 0 + 1 + ... + 65535 = 2147450880 < 2147483647 sum(base, max) }) suite.add('from small to big', function bigSum () { var base = 32768 - var max = 98304 + var max = 98303 + // 32768 + 32769 + ... + 98303 = 4294934528 > 2147483647 sum(base, max) }) suite.add('all big', function bigSum () { - var base = 65536 - var max = 131071 + var base = 2147483648 + var max = 2147549183 + // 2147483648 > 2147483647 sum(base, max) }) diff --git a/bench/object-creation.js b/bench/object-creation.js index 8e0412c..1e8fb32 100644 --- a/bench/object-creation.js +++ b/bench/object-creation.js @@ -14,17 +14,18 @@ function MyCtor (x) { this.x = x } +var obj suite.add('literal', function base () { - var obj = { x: 1 } + obj = { x: 1 } }) suite.add('class', function allNums () { - var obj = new MyClass(1) + obj = new MyClass(1) }) suite.add('constructor', function allNums () { - var obj = new MyCtor(1) + obj = new MyCtor(1) }) suite.on('cycle', () => runs = 0)