-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathb-es6-map.js
More file actions
71 lines (61 loc) · 1.7 KB
/
b-es6-map.js
File metadata and controls
71 lines (61 loc) · 1.7 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
70
71
'use strict';
const benchmark = require('./2-benchmark.js');
const cities = new Map();
cities.set('Athens', { name: 'Афины', population: 664046 });
cities.set('Rome', { name: 'Рим', population: 2627000 });
cities.set('London', { name: 'Лондон', population: 8674000 });
cities.set('Beijing', { name: 'Пекин', population: 11510000 });
cities.set('Kiev', { name: 'Киев', population: 2804000 });
cities.set('Riga', { name: 'Рига', population: 643615 });
const citiesOld = {
Athens: { name: 'Афины', population: 664046 },
Rome: { name: 'Рим', population: 2627000 },
London: { name: 'Лондон', population: 8674000 },
Beijing: { name: 'Пекин', population: 11510000 },
Kiev: { name: 'Киев', population: 2804000 },
Riga: { name: 'Рига', population: 643615 }
};
const testForInHash = () => {
const arr = [];
for (const key in citiesOld) {
arr.push([ citiesOld[key], key ]);
}
};
const testForEach = () => {
const arr = [];
cities.forEach((value, key) => {
arr.push([ value, key ]);
});
};
const testForOf = () => {
const arr = [];
for (const [key, value] of cities) {
arr.push([ value, key ]);
}
};
const testForOfKeys = () => {
const arr = [];
for (const key of cities.keys()) {
arr.push(key);
}
};
const testForOfValues = () => {
const arr = [];
for (const value of cities.values()) {
arr.push(value);
}
};
const testForOfEntries = () => {
const arr = [];
for (const [key, value] of cities.entries()) {
arr.push([ key, value ]);
}
};
benchmark.do(1000000, [
testForInHash,
testForEach,
testForOf,
testForOfKeys,
testForOfValues,
testForOfEntries,
]);