Skip to content

Instantly share code, notes, and snippets.

@taxilian
Created June 29, 2016 18:35
Show Gist options
  • Save taxilian/7807409f1fba6abfdc11c4da04975984 to your computer and use it in GitHub Desktop.
Save taxilian/7807409f1fba6abfdc11c4da04975984 to your computer and use it in GitHub Desktop.
/* jshint esversion: 6 */
"use strict";
const Benchmark = require('benchmark');
let suite = new Benchmark.Suite;
class Thingy {
constructor(obj) {
this.obj = obj;
}
get a() { return this.obj.a; }
get b() { return this.obj.b; }
get c() { return this.obj.c; }
}
suite.add('raw object', function() {
let o = {
a: 1,
b: 2,
c: 3
};
let b = o.a + o.c;
}).add('raw copied object', function() {
let o1 = {
a: 1,
b: 2,
c: 3
};
let o = [];
for (let fldname in o1) {
o[fldname] = o1[fldname];
}
let b = o.a + o.c;
}).add('new object', () => {
let o = new Thingy({
a: 1,
b: 2,
c: 3
});
const b = o.a + o.c;
}).on('cycle', function(event) {
console.log(String(event.target));
}).on('complete', function(event) {
console.log('Fastest is ' + this.filter('fastest').map('name'));
}).run({async: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment