Skip to content

Instantly share code, notes, and snippets.

@amitosdev
Created December 28, 2017 11:40
Show Gist options
  • Save amitosdev/32d812e0339b0f08475cc6ee389dfed1 to your computer and use it in GitHub Desktop.
Save amitosdev/32d812e0339b0f08475cc6ee389dfed1 to your computer and use it in GitHub Desktop.
Js stack trace benchmark
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