-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
82 lines (59 loc) · 1.9 KB
/
test.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
const millionTimes = 1_000_000;
const arrayWithMillionZeros = Array(millionTimes).fill(0);
// Traditional while loop
console.time('Traditional while loop time');
let iterator = 0;
while (iterator < millionTimes) {
iterator++;
}
console.timeEnd('Traditional while loop time');
// Traditional do-while loop
console.time('Traditional do-while loop time');
let index = 0;
do {
index++;
} while (index < millionTimes);
console.timeEnd('Traditional do-while loop time');
// Traditional for loop
console.time('Traditional for loop time');
for (let index = 0; index < millionTimes; index++) {}
console.timeEnd('Traditional for loop time');
// For of loop
console.time('For of loop time');
for (let value of arrayWithMillionZeros) {}
console.timeEnd('For of loop time');
// For in loop
console.time('For in loop time');
for (let value in arrayWithMillionZeros) {}
console.timeEnd('For in loop time');
// Map method
console.time('Map method time');
arrayWithMillionZeros.map(() => {});
console.timeEnd('Map method time');
// Filter method
console.time('Filter method time');
arrayWithMillionZeros.filter(() => {});
console.timeEnd('Filter method time');
// Reduce method
console.time('Reduce method time');
arrayWithMillionZeros.reduce(() => {});
console.timeEnd('Reduce method time');
// Sort method
console.time('Sort method time');
arrayWithMillionZeros.sort(() => {});
console.timeEnd('Sort method time');
// Every method
console.time('Every method time');
arrayWithMillionZeros.every(value => value == 0);
console.timeEnd('Every method time');
// Some method
console.time('Some method time');
arrayWithMillionZeros.some(() => {});
console.timeEnd('Some method time');
// Chaining methods
console.time('Chaining methods time');
arrayWithMillionZeros.map(() => {})
.filter(() => {})
.sort(() => {})
.forEach(() => {});
console.timeEnd('Chaining methods time');