Skip to content

Instantly share code, notes, and snippets.

@mcollina
Created July 28, 2017 23:02
Show Gist options
  • Save mcollina/0bbcca999f7c190d97009165b7913824 to your computer and use it in GitHub Desktop.
Save mcollina/0bbcca999f7c190d97009165b7913824 to your computer and use it in GitHub Desktop.
'use strict'
var benchmark = require('benchmark')
var suite = new benchmark.Suite()
var runs = 0
class MyClass {
constructor (x) {
this.x = x
}
}
function MyCtor (x) {
this.x = x
}
var res = 0
suite.add('literal', function base () {
var obj = { x: Math.random() }
res = obj.x
})
suite.add('class', function allNums () {
var obj = new MyClass(Math.random())
res = obj.x
})
suite.add('constructor', function allNums () {
var obj = new MyCtor(Math.random())
res = obj.x
})
suite.on('cycle', () => runs = 0)
suite.on('complete', require('./print'))
suite.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment