Skip to content

Instantly share code, notes, and snippets.

@eldargab
Forked from chowey/bench.js
Created April 20, 2012 15:22
Show Gist options
  • Save eldargab/2429577 to your computer and use it in GitHub Desktop.
Save eldargab/2429577 to your computer and use it in GitHub Desktop.
Benchmark str concatenation
var Benchmark = require('benchmark')
var suite = new Benchmark.Suite
suite
.add('push', function () {
var a = []
a.push("Lorem")
a.push("ipsum")
a.push("dolor")
a.push("sit")
a.push("amet,")
a.push("consectetur")
a.push("adipisicing")
a.push("elit,")
a.push("sed")
a.push("do")
a.push("eiusmod")
a.push("tempor")
a.push("incididunt")
a.push("ut")
a.push("labore")
a.push("et")
a.push("dolore")
a.push("magna")
a.push("aliqua.")
a.push("Ut")
a.push("enim")
a.push("ad")
a.push("minim")
a.push("veniam,")
a.push("quis")
a.push("nostrud")
a.push("exercitation")
a.push("ullamco")
a.push("laboris")
a.push("nisi")
a.push("ut")
a.push("aliquip")
a.push("ex")
a.push("ea")
a.push("commodo")
a.push("consequat.")
a.push("Duis")
a.push("aute")
a.push("irure")
a.push("dolor")
a.push("in")
a.push("reprehenderit")
a.push("in")
a.push("voluptate")
a.push("velit")
a.push("esse")
a.push("cillum")
a.push("dolore")
a.push("eu")
a.push("fugiat")
a.push("nulla")
a.push("pariatur.")
a.push("Excepteur")
a.push("sint")
a.push("occaecat")
a.push("cupidatat")
a.push("non")
a.push("proident,")
a.push("sunt")
a.push("in")
a.push("culpa")
a.push("qui")
a.push("officia")
a.push("deserunt")
a.push("mollit")
a.push("anim")
a.push("id")
a.push("est")
a.push("laborum")
new Buffer(a.join())
})
.add('add', function () {
var s = ""
s += "Lorem"
s += "ipsum"
s += "dolor"
s += "sit"
s += "amet,"
s += "consectetur"
s += "adipisicing"
s += "elit,"
s += "sed"
s += "do"
s += "eiusmod"
s += "tempor"
s += "incididunt"
s += "ut"
s += "labore"
s += "et"
s += "dolore"
s += "magna"
s += "aliqua."
s += "Ut"
s += "enim"
s += "ad"
s += "minim"
s += "veniam,"
s += "quis"
s += "nostrud"
s += "exercitation"
s += "ullamco"
s += "laboris"
s += "nisi"
s += "ut"
s += "aliquip"
s += "ex"
s += "ea"
s += "commodo"
s += "consequat."
s += "Duis"
s += "aute"
s += "irure"
s += "dolor"
s += "in"
s += "reprehenderit"
s += "in"
s += "voluptate"
s += "velit"
s += "esse"
s += "cillum"
s += "dolore"
s += "eu"
s += "fugiat"
s += "nulla"
s += "pariatur."
s += "Excepteur"
s += "sint"
s += "occaecat"
s += "cupidatat"
s += "non"
s += "proident,"
s += "sunt"
s += "in"
s += "culpa"
s += "qui"
s += "officia"
s += "deserunt"
s += "mollit"
s += "anim"
s += "id"
s += "est"
s += "laborum"
new Buffer(s)
})
.on('cycle', function (event, bench) {
console.log(bench.toString());
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').pluck('name'))
})
.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment