Skip to content

Instantly share code, notes, and snippets.

@justinvdm
Last active May 13, 2019 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinvdm/d77ffd9447763dfb423271ef9a6c7d36 to your computer and use it in GitHub Desktop.
Save justinvdm/d77ffd9447763dfb423271ef9a6c7d36 to your computer and use it in GitHub Desktop.
const assert = require("assert");
class V {
constructor(v) {
this.v = v;
}
}
suite("fn-create-overhead", () => {
const { N = 100000 } = require("./conf");
before(() => {});
bench("arrow", () => {
let i = -1;
let v = null;
while (++i < N) {
const vv = v;
v = () => vv + 1;
}
});
bench("function", () => {
let i = -1;
let v = null;
while (++i < N) {
const vv = v;
v = function() {
return vv + 1;
};
}
});
bench("object", () => {
let i = -1;
let v = null;
while (++i < N) v = { v };
});
bench("class", () => {
let i = -1;
let v = null;
while (++i < N) v = new V(v);
});
bench("inlined class", () => {
let i = -1;
let v = null;
class InlinedV {
constructor(v) {
this.v = v;
}
}
while (++i < N) v = new InlinedV(v);
});
});
fn-create-overhead
arrow .......................................... 112 op/s
function ....................................... 145 op/s
object ......................................... 1,082 op/s
class .......................................... 1,067 op/s
inlined class .................................. 300 op/s
Suites: 1
Benches: 5
Elapsed: 4,133.61 ms
let N;
if (process.env.BENCH_N) N = process.env.BENCH_N;
if (process.env.TEST) {
set('type', 'static');
set('iterations', 1);
N = 1;
}
module.exports = {
N
};
{
"name": "bench-fn-create-overhead",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"drip": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/drip/-/drip-1.1.0.tgz",
"integrity": "sha1-zO+x5obYb8EVtwyewSb4+HG9/X4=",
"dev": true,
"requires": {
"tea-concat": "0.1.0"
}
},
"electron": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/electron/-/electron-0.4.1.tgz",
"integrity": "sha1-p4oFGniC9OVC1uIH2KGnMHazAUQ=",
"dev": true,
"requires": {
"drip": "1.1.x"
}
},
"matcha": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/matcha/-/matcha-0.7.0.tgz",
"integrity": "sha1-E/gFQJs3vlcDLIRYZDvxUjumjdo=",
"dev": true,
"requires": {
"electron": "0.4.x",
"v8-argv": "0.1.x"
}
},
"tea-concat": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/tea-concat/-/tea-concat-0.1.0.tgz",
"integrity": "sha1-6i6QdAD914pjNM4CD6PGlQLZnoQ=",
"dev": true
},
"v8-argv": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/v8-argv/-/v8-argv-0.1.0.tgz",
"integrity": "sha1-rfd3pS29w9qciclGXlntXzy22ak=",
"dev": true
}
}
}
{
"name": "bench-fn-create-overhead",
"version": "1.0.0",
"description": "",
"main": "__bench-fn-create-overhead.js",
"scripts": {
"test": "TEST=1 npm run bench",
"start": "npm run bench --silent | tee _results.txt",
"bench": "matcha -R plain *.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"matcha": "^0.7.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment