Skip to content

Instantly share code, notes, and snippets.

@axdg
Last active February 2, 2016 08:27
Show Gist options
  • Save axdg/3b9de883701acd7fabb3 to your computer and use it in GitHub Desktop.
Save axdg/3b9de883701acd7fabb3 to your computer and use it in GitHub Desktop.
front-matter-delim-parsing
var Benchmark = require('benchmark');
var re = /^---\r?\n/;
var text = '---\r\nsomeotherpartofthestring';
var suite = new Benchmark.Suite;
suite.add('String.prototype.indexOf()', function() {
return (text.indexOf('---\n') !== -1) ||
(text.indexOf('---\r\n') !== -1);
});
suite.add('String.prototype.test()', function() {
return re.test(text);
});
suite.add('String.prototype.search()', function() {
return text.search(re);
});
suite.on('cycle', function(e) {
console.log(String(e.target));
});
suite.on('complete', function() {
console.log(' ');
});
suite.run();
{
"name": "strop-perf-fm",
"version": "0.0.1",
"description": "front-matter-delim-parsing",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"benchmark": "node index.js >> results.txt || true"
},
"author": "axdg <axdg@dfant.asia>",
"license": "MIT",
"dependencies": {
"benchmark": "^2.1.0"
}
}
String.prototype.indexOf() x 6,081,685 ops/sec ±2.25% (76 runs sampled)
String.prototype.test() x 14,902,837 ops/sec ±2.11% (75 runs sampled)
String.prototype.search() x 10,944,121 ops/sec ±4.30% (70 runs sampled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment