Last active
October 13, 2015 09:57
-
-
Save Tom32i/821cbd861ba2beafd0f6 to your computer and use it in GitHub Desktop.
Revisions
-
Tom32i revised this gist
Oct 13, 2015 . 1 changed file with 12 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,24 +2,31 @@ 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 }*/); -
Tom32i revised this gist
Oct 13, 2015 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,11 +6,10 @@ var suite = new Benchmark.Suite; suite .add('function#A', function() { // Version A }) .add('function#B', function() { // Version B }) // add listeners .on('start', function() { -
Tom32i revised this gist
Oct 13, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,6 @@ </head> <body> <script src="node_modules/benchmark/benchmark.js"></script> <script src="benchmark.js"></script> </body> </html> -
Tom32i revised this gist
Oct 13, 2015 . 3 changed files with 27 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ # Benchmark in node.js & browser ## Install npm install ## Usage: ### Node: node benchmark.js ### Browser: Navigate to index.html and open console. 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ <title>Benchmark</title> </head> <body> <script src="node_modules/benchmark/benchmark.js"></script> <script src="index.js"></script> </body> </html> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ { "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" } } -
Tom32i created this gist
Oct 13, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ if (typeof(require) !== 'undefined') { var Benchmark = require('benchmark'); } var suite = new Benchmark.Suite; suite .add('function#A', function() { return Math.sqrt(Math.pow(point.x1 - point.x2, 2) + Math.pow(point.y1 - point.y2, 2)); }) .add('function#B', function() { var x = point.x1 - point.x2, y = point.y1 - point.y2; return Math.sqrt(x*x + y*y); }) // add listeners .on('start', function() { console.log('Started'); }) .on('cycle', function(event) { console.log(String(event.target)); }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').pluck('name')); }) // run async .run({ 'async': true }); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ <!DOCTYPE html> <html> <head> <title>Benchmark</title> </head> <body> <script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> <script src="index.js"></script> </body> </html>