Created
July 28, 2017 22:51
-
-
Save mcollina/40e91ad55ae9c3b0131c2a8b79387dfe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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 | |
function doSomething (obj) { | |
res = obj.x | |
} | |
suite.add('literal', function base () { | |
var obj = { x: 1 } | |
doSomething(obj) | |
}) | |
suite.add('class', function allNums () { | |
var obj = new MyClass(1) | |
doSomething(obj) | |
}) | |
suite.add('constructor', function allNums () { | |
var obj = new MyCtor(1) | |
doSomething(obj) | |
}) | |
var literal = { x: 1 } | |
suite.add('create', function allNums () { | |
var obj = Object.create(literal) | |
doSomething(obj) | |
}) | |
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