-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiteration.js
More file actions
69 lines (61 loc) · 1.07 KB
/
iteration.js
File metadata and controls
69 lines (61 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const _ = require('lodash')
const a = {
a: 1,
b: 1,
c: 1,
d: 1,
e: 1,
f: 1,
g: 1
}
function init() {
return new Promise((resolve, reject) => {
for (let i = 1; i < 100000; i++) {
a[i] = i
if (i === 99999) {
console.log('init')
return resolve()
}
}
})
}
async function test() {
console.log('tes-1')
for (const key of Object.keys(a)) {
if (key === 'a') continue
await time()
console.log(key)
}
console.log('tes-2')
}
function time() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, 3000)
})
}
function test2() {
console.log('test-1')
_.forEach(a, async (val, key) => {
if (key === 'a') return
await time()
console.log(key)
})
console.log('test-2')
}
async function test3() {
await init()
console.log(Object.keys(a).length)
console.time('tes--1')
for (const key in a) {
a[key] = 'a'
}
console.timeEnd('tes--1')
console.time('tes--2')
for (const key of Object.keys(a)) {
a[key] = 'a'
}
console.timeEnd('tes--2')
}
test3()