forked from sadfsdfdsa/performance-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops-test-object.mjs
More file actions
35 lines (28 loc) · 766 Bytes
/
loops-test-object.mjs
File metadata and controls
35 lines (28 loc) · 766 Bytes
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
import { trackPerformance } from './performanceWrapper.mjs'
const propsNumber = 1000 * 1000 * 1
const objectTest = {}
const filler = () => {
for (let index = 0; index < propsNumber; index++) {
const key = `prop${index + 1}`
const value = `value${index + 1}`
objectTest[key] = value
}
}
filler()
const executeTestCase1 = () => {
const cache = []
for (const key in objectTest) {
const element = objectTest[key]
cache.push(element)
}
}
// ! Always better
const executeTestCase2 = () => {
const cache = []
for (const iterator of Object.keys(objectTest)) {
const element = objectTest[iterator]
cache.push(element)
}
}
trackPerformance(executeTestCase1, 'FOR IN')
trackPerformance(executeTestCase2, 'FOR OF Object.keys')