Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发现个关于for in的问题,想请教下 #4

Open
senlin-wei opened this issue Jul 11, 2016 · 1 comment
Open

发现个关于for in的问题,想请教下 #4

senlin-wei opened this issue Jul 11, 2016 · 1 comment

Comments

@senlin-wei
Copy link

源码(对象第一个属性不同):
var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, '-': 6};
var objN = {1: 1, b: 2, c: 3, d: 4, e: 5, '-': 6};
suite
.add('for .. in ..:', function () {
for (var k in obj) {
obj[k]
}
})
.add('for .. in N :', function () {
for (var k in objN) {
obj[k]
}
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });

结果:
for .. in ..: x 12,439,181 ops/sec ±5.58% (75 runs sampled)
for .. in N : x 870,694 ops/sec ±6.75% (70 runs sampled)
Fastest is for .. in ..:
为什么用数字作为key,效率会这么低呢

@alsotang
Copy link
Owner

真不知道。。

2016-07-11 17:31 GMT+08:00 senlin-wei [email protected]:

源码(对象第一个属性不同):
var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, '-': 6};
var objN = {1: 1, b: 2, c: 3, d: 4, e: 5, '-': 6};
suite
.add('for .. in ..:', function () {
for (var k in obj) {
obj[k]
}
})
.add('for .. in N :', function () {
for (var k in objN) {
obj[k]
}
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });

结果:
for .. in ..: x 12,439,181 ops/sec ±5.58% (75 runs sampled)
for .. in N : x 870,694 ops/sec ±6.75% (70 runs sampled)
Fastest is for .. in ..:
为什么用数字作为key,效率会这么低呢


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#4, or mute the thread
https://github.com/notifications/unsubscribe/ABGB76bOe4dodYEBMjF5q_wM5lzbocVyks5qUg2BgaJpZM4JJL3C
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants