Created
April 13, 2012 13:47
-
-
Save chowey/2376965 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var Benchmark = require('benchmark'), | |
| jade = require('../'), | |
| fs = require('fs'); | |
| // Test cases | |
| var cases = fs.readdirSync('cases').filter(function(file){ | |
| return ~file.indexOf('.jade'); | |
| }), | |
| pretty = {}, | |
| prettier = {}, | |
| locals = { title: 'Jade' }; | |
| cases.forEach(function(name){ | |
| var path = 'cases/' + name; | |
| var str = fs.readFileSync(path, 'utf8'); | |
| var fn = jade.compile(str, { filename: path, pretty: true }); | |
| pretty[name] = jade.compile(str, { filename: path, pretty: true }); | |
| prettier[name] = jade.compile(str, { filename: path, prettypretty: true }); | |
| }); | |
| var suite = new Benchmark.Suite; | |
| suite | |
| .add('pretty', function () { | |
| for (name in pretty) | |
| pretty[name](locals); | |
| }) | |
| .add('prettier', function () { | |
| for (name in prettier) | |
| prettier[name](locals); | |
| }) | |
| .on('cycle', function (event, bench) { | |
| console.log(bench.toString()); | |
| }) | |
| .on('complete', function () { | |
| console.log('Fastest is ' + this.filter('fastest').pluck('name')); | |
| }) | |
| .run(); |
Author
Author
Results on my box are:
c:\cloned\jade\test>node test
pretty x 1,058 ops/sec ±0.52% (60 runs sampled)
prettier x 858 ops/sec ±0.92% (59 runs sampled)
Fastest is pretty
So "prettier" takes longer by about 25%.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run from jade/test