我玩过jsperf.com,发现prototyped函数比"default"声明函数慢40倍.
String.prototype.contains = function(s){ return !!~this.indexOf(s) } = 220K ops/s
与
function isContains(str, s) { return !!~str.indexOf(s) } = 8.5KK ops/s
PS我知道原型修改不是最好的情况,可以命名为'猴子修补':)
我正在尝试设置并运行microtime包,但节点引发了错误:
npm install microtime
ubuntu@ubuntu-desktop:~$ node
> var microtime = require('microtime')
Error: Could not load the bindings file. Tried:
-> /home/ubuntu/node_modules/microtime/build/Debug/microtime.node
-> /home/ubuntu/node_modules/microtime/build/Release/microtime.node
-> /home/ubuntu/node_modules/microtime/out/Debug/microtime.node
-> /home/ubuntu/node_modules/microtime/Debug/microtime.node
-> /home/ubuntu/node_modules/microtime/out/Release/microtime.node
-> /home/ubuntu/node_modules/microtime/Release/microtime.node
-> /home/ubuntu/node_modules/microtime/build/default/microtime.node
-> /home/ubuntu/node_modules/microtime/compiled/0.6/linux/ia32/microtime.node
at bindings (/home/ubuntu/node_modules/microtime/node_modules/bindings/bindings.js:82:13)
at Object.<anonymous> (/home/ubuntu/node_modules/microtime/index.js:1:95)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at repl:1:17
at REPLServer.eval (repl.js:80:21)
Run Code Online (Sandbox Code Playgroud)
路径似乎有问题,但我不知道在哪里挖掘来解决这个问题(我是linux新手)
我的担心是: ubuntu 10.04, node 0.6.13, npm 1.1.10
2 @ Linus:嗯,我刚刚尝试重新安装microtime,现在它出错(但第一次没有):
ubuntu@ubuntu-desktop:~/app1$ npm …Run Code Online (Sandbox Code Playgroud)