小编mje*_*jey的帖子

为什么原型函数比默认声明函数慢40倍?

我玩过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

这是一个jsperf测试用例

PS我知道原型修改不是最好的情况,可以命名为'猴子修补':)

javascript performance prototype

6
推荐指数
1
解决办法
1084
查看次数

节点看不到包,路径错误

我正在尝试设置并运行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)

path node.js npm

2
推荐指数
1
解决办法
3896
查看次数

标签 统计

javascript ×1

node.js ×1

npm ×1

path ×1

performance ×1

prototype ×1