Created
February 5, 2015 04:39
-
-
Save Alex1990/f29b874ef5e33119cf2e to your computer and use it in GitHub Desktop.
A simple function to test performance.
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
| /** | |
| * A simple function to test performance. | |
| */ | |
| function benchmark() { | |
| var tests = Array.prototype.slice.call(arguments); | |
| var length = tests.length; | |
| var startTimes = Array(length); | |
| var result = Array(length); | |
| var times = typeof benchmark.times === 'number' ? benchmark.times/2 : 5000; | |
| for (var i = 0; i < length; i++) { | |
| startTimes[i] = new Date(); | |
| for (var j = 0; j < times; j++) { | |
| tests[i](); | |
| } | |
| result[i] = new Date() - startTimes[i]; | |
| } | |
| for (i = length - 1; i >=0; i--) { | |
| startTimes[i] = new Date(); | |
| for (var j = 0; j < times; j++) { | |
| tests[i](); | |
| } | |
| result[i] += new Date() - startTimes[i]; | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment