Created
September 8, 2015 12:50
-
-
Save makenowjust/85464857bfd66ebfdc22 to your computer and use it in GitHub Desktop.
benchmark Function#bind vs prototype
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 X(x, y) { | |
| this.x = x; | |
| this.y = y; | |
| if (process.env.BIND) { | |
| this.n = this.n.bind(this); | |
| } | |
| } | |
| X.prototype.n = function n() { | |
| return Math.sqrt(this.x * this.x + this.y * this.y); | |
| } | |
| var | |
| i, j, x, | |
| iter = 1000000 * 1000; | |
| console.time('loop'); | |
| x = new X(Math.random(), Math.random()); | |
| for (i = 0; i < iter; i++) { | |
| x.n(); | |
| } | |
| console.timeEnd('loop'); | |
| // env BIND=yes node bench-bind.js | |
| // するとものすごく重くなる(いつまで経っても終わらないので計測できなかった) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment