Permalink
Browse files

Benchmarks with node-bench

  • Loading branch information...
tj committed May 17, 2010
1 parent 5561c5a commit c383b48bf72438d726c0af13c983d48c7d32a158
Showing with 25 additions and 58 deletions.
  1. +1 −1 Makefile
  2. +6 −10 Readme.md
  3. +18 −47 benchmarks/run.js
View
@@ -3,6 +3,6 @@ test:
@node spec/node.js
benchmark:
- @node benchmarks/run.js
+ @node-bench benchmarks/run.js
.PHONY: test benchmark
View
@@ -13,17 +13,13 @@
## About
Benchmarks rendering the same 21 line haml file located at _benchmarks/page.haml_,
- shows that this library is nearly **400% faster**.
+ shows that this library is nearly **65%** or **3 times** faster than haml-js.
- 3000 times
- null: 0 seconds
-
- haml.js: 1.767 seconds
- haml.js cached: 0.028 seconds
-
- haml-js: 5.123 seconds
- haml-js cached: 0.076 seconds
- haml-js cached / optimized: 0.06 seconds
+ Winner: haml.js
+ Compared with next highest (haml-js), it's:
+ 65.39% faster
+ 2.89 times as fast
+ 0 order(s) of magnitude faster
Haml.js attempts to comply with the original [Haml](http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html)
implementation as well as possible. There are no magic "plugins" like
View
@@ -1,54 +1,25 @@
-var sys = require('sys'),
- fs = require('fs'),
+var fs = require('fs'),
haml = require('../lib/haml'),
hamlJS = require('./haml-js/lib/haml'),
page = fs.readFileSync('benchmarks/page.haml')
- times = 3000
-
-function bm(label, fn) {
- var start = +new Date
- fn()
- var duration = ((+new Date) - start) / 1000
- sys.puts(label + ': ' + duration + ' seconds')
-}
-
-sys.puts(times + ' times')
-
-bm('null', function(){
- var n = times
- while (n--) ;
-})
-
-sys.puts('')
-
-bm('haml.js', function(){
- var n = times
- while (n--) haml.render(page)
-})
-
-bm('haml.js cached', function(){
- var n = times
- while (n--) haml.render(page, { cache: true, filename: 'page.haml' })
-})
-
-sys.puts('')
-
-bm('haml-js', function(){
- var n = times
- while (n--) hamlJS.render(page)
-})
var js = hamlJS.compile(page)
-bm('haml-js cached', function(){
- var n = times
- while (n--) hamlJS.execute(js)
-})
-
-var js = hamlJS.optimize(hamlJS.compile(page))
-
-bm('haml-js cached / optimized', function(){
- var n = times
- while (n--) hamlJS.execute(js)
-})
+exports.compare = {
+ 'haml.js': function(){
+ haml.render(page)
+ },
+ 'haml.js cached': function(){
+ haml.render(page, { cache: true, filename: 'page.haml' })
+ },
+ 'haml-js': function(){
+ hamlJS.render(page)
+ },
+ 'haml-js cached': function(){
+ hamlJS.execute(js)
+ },
+ 'haml-js cached / optimized': function(){
+ hamlJS.execute(js)
+ }
+}

0 comments on commit c383b48

Please sign in to comment.