Skip to content

Commit

Permalink
Fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Jul 28, 2017
1 parent 3c511ee commit f79a270
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 9 additions & 6 deletions bench/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
7 changes: 4 additions & 3 deletions bench/object-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f79a270

Please sign in to comment.