Created
July 28, 2017 23:02
-
-
Save mcollina/0bbcca999f7c190d97009165b7913824 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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