more benchmarks

This commit is contained in:
Christopher Jeffrey 2011-10-22 08:36:34 -05:00
parent 9ff55ae9d7
commit 628994fec1

View File

@ -124,16 +124,6 @@ var bench = function() {
var marked = require('../'); var marked = require('../');
main.bench('marked', marked); main.bench('marked', marked);
/**
* There's two ways to benchmark showdown here.
* The first way is to create a new converter
* every time, this will renew any closured
* variables. It is the "proper" way of using
* showdown. However, for this benchmark,
* I will use the completely improper method
* which is must faster, just to be fair.
*/
var showdown = (function() { var showdown = (function() {
var Showdown = require('showdown').Showdown; var Showdown = require('showdown').Showdown;
var convert = new Showdown.converter(); var convert = new Showdown.converter();
@ -141,7 +131,16 @@ var bench = function() {
return convert.makeHtml(text); return convert.makeHtml(text);
}; };
})(); })();
main.bench('showdown', showdown); main.bench('showdown (reuse converter)', showdown);
var showdown_slow = (function() {
var Showdown = require('showdown').Showdown;
return function(text) {
var convert = new Showdown.converter();
return convert.makeHtml(text);
};
})();
main.bench('showdown (new converter)', showdown_slow);
var markdownjs = require('markdown-js'); var markdownjs = require('markdown-js');
main.bench('markdown-js', function(text) { main.bench('markdown-js', function(text) {
@ -149,6 +148,11 @@ var bench = function() {
}); });
}; };
var time = function() {
var marked = require('../');
main.bench('marked', marked);
};
var old_bench = function() { var old_bench = function() {
var text = fs.readFileSync(__dirname + '/main.md', 'utf8'); var text = fs.readFileSync(__dirname + '/main.md', 'utf8');
@ -311,6 +315,8 @@ var pretty = (function() {
if (!module.parent) { if (!module.parent) {
if (~process.argv.indexOf('--bench')) { if (~process.argv.indexOf('--bench')) {
bench(); bench();
} else if (~process.argv.indexOf('--time')) {
time();
} else if (~process.argv.indexOf('--old_bench')) { } else if (~process.argv.indexOf('--old_bench')) {
old_bench(); old_bench();
} else if (~process.argv.indexOf('--old_test')) { } else if (~process.argv.indexOf('--old_test')) {