Created
June 20, 2016 19:59
-
-
Save hyperlogic/1881148fe1f0a0353dc3fb6e71fa7029 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
| function someOperation(x) { } | |
| function looped(array, op) { | |
| var i, length = array.length; | |
| for (i = 0; i < length; i++) { | |
| op(array[i]); | |
| } | |
| } | |
| function mapped(array, op) { | |
| array.forEach(op); | |
| } | |
| function timeIt(n, m, crawler, op) { | |
| var array = new Array(m), i, start, elapsed; | |
| // jit the crawler | |
| crawler(array, op); | |
| start = Date.now(); | |
| for (i = 0; i < n; i++) { | |
| crawler(array, someOperation); | |
| } | |
| elapsed = Date.now() - start; | |
| print('time:', elapsed); | |
| } | |
| timeIt(100000, 0, looped, someOperation); | |
| timeIt(100000, 0, mapped, someOperation); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment