Created
December 28, 2017 11:40
-
-
Save amitosdev/32d812e0339b0f08475cc6ee389dfed1 to your computer and use it in GitHub Desktop.
Js stack trace benchmark
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
const Benchmark = require('benchmark') | |
const suite = new Benchmark.Suite() | |
const stack = require('callsite') | |
const stackTrace = require('stack-trace') | |
suite.add('with callsite module', function () { | |
class Test { | |
constructor(name) { | |
this.name = name | |
} | |
doSomeThing(value) { | |
logs(55) | |
} | |
} | |
function logs(value) { | |
let site = stack() | |
let funcName = site[1].getFunctionName() | |
} | |
const test = new Test('somVal') | |
test.doSomeThing(44) | |
}) | |
.add('with node-stack-trace module', function () { | |
class Test { | |
constructor(name) { | |
this.name = name | |
} | |
doSomeThing(value) { | |
logs(55) | |
} | |
} | |
function logs(value) { | |
let site = stackTrace.get() | |
let funcName = site[0].getFunctionName() | |
} | |
const test = new Test('somVal') | |
test.doSomeThing(44) | |
}) | |
.add('without stack trace', function () { | |
class Test { | |
constructor(name) { | |
this.name = name | |
} | |
doSomeThing(value) { | |
logs(value) | |
} | |
} | |
function logs(value) { | |
let funcName = 'no name' | |
} | |
const test = new Test('somVal') | |
test.doSomeThing(44) | |
}) | |
// add listeners | |
.on('cycle', function (event) { | |
console.log(String(event.target)) | |
}) | |
.on('complete', function () { | |
console.log(`Fastest is ${this.filter('fastest').map('name')}`) | |
}) | |
// run async | |
.run({ 'async': true }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment