Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix benchmarks #6

Merged
merged 1 commit into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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