npm install
node benchmark.js
Navigate to index.html and open console.
| if (typeof(require) !== 'undefined') { | |
| var Benchmark = require('benchmark'); | |
| } | |
| var suite = new Benchmark.Suite('My benchmark'); | |
| // Functions to compare | |
| suite | |
| .add('function#A', function() { | |
| // Version A | |
| }) | |
| .add('function#B', function() { | |
| // Version B | |
| }) | |
| // Listeners | |
| .on('start', function() { | |
| console.log('Started "%s"', this.name); | |
| if (typeof(document) !== 'undefined') { | |
| document.title = this.name; | |
| } | |
| }) | |
| .on('cycle', function(event) { | |
| console.log(String(event.target)); | |
| }) | |
| .on('complete', function() { | |
| console.log('Fastest is ' + this.filter('fastest').pluck('name')); | |
| }) | |
| // Run | |
| .run(/*{ 'async': true }*/); |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Benchmark</title> | |
| </head> | |
| <body> | |
| <script src="node_modules/benchmark/benchmark.js"></script> | |
| <script src="benchmark.js"></script> | |
| </body> | |
| </html> |
| { | |
| "name": "benchmark", | |
| "version": "1.0.0", | |
| "description": "A node.js + browser compatible benchmark suite", | |
| "main": "benchmark.js", | |
| "author": "Thomas Jarrand", | |
| "license": "MIT", | |
| "dependencies": { | |
| "benchmark": "^1.0.0", | |
| "microtime": "^2.0.0" | |
| } | |
| } |