Skip to content

Commit a6e69f8

Browse files
committed
benchmark: add more options to map-bench
PR-URL: #11930 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d9b0e4c commit a6e69f8

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

benchmark/es/map-bench.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ const common = require('../common.js');
44
const assert = require('assert');
55

66
const bench = common.createBenchmark(main, {
7-
method: ['object', 'nullProtoObject', 'fakeMap', 'map'],
7+
method: [
8+
'object', 'nullProtoObject', 'nullProtoLiteralObject', 'storageObject',
9+
'fakeMap', 'map'
10+
],
811
millions: [1]
912
});
1013

@@ -36,6 +39,37 @@ function runNullProtoObject(n) {
3639
bench.end(n / 1e6);
3740
}
3841

42+
function runNullProtoLiteralObject(n) {
43+
const m = { __proto__: null };
44+
var i = 0;
45+
bench.start();
46+
for (; i < n; i++) {
47+
m['i' + i] = i;
48+
m['s' + i] = String(i);
49+
assert.strictEqual(String(m['i' + i]), m['s' + i]);
50+
m['i' + i] = undefined;
51+
m['s' + i] = undefined;
52+
}
53+
bench.end(n / 1e6);
54+
}
55+
56+
function StorageObject() {}
57+
StorageObject.prototype = Object.create(null);
58+
59+
function runStorageObject(n) {
60+
const m = new StorageObject();
61+
var i = 0;
62+
bench.start();
63+
for (; i < n; i++) {
64+
m['i' + i] = i;
65+
m['s' + i] = String(i);
66+
assert.strictEqual(String(m['i' + i]), m['s' + i]);
67+
m['i' + i] = undefined;
68+
m['s' + i] = undefined;
69+
}
70+
bench.end(n / 1e6);
71+
}
72+
3973
function fakeMap() {
4074
const m = {};
4175
return {
@@ -84,6 +118,12 @@ function main(conf) {
84118
case 'nullProtoObject':
85119
runNullProtoObject(n);
86120
break;
121+
case 'nullProtoLiteralObject':
122+
runNullProtoLiteralObject(n);
123+
break;
124+
case 'storageObject':
125+
runStorageObject(n);
126+
break;
87127
case 'fakeMap':
88128
runFakeMap(n);
89129
break;

0 commit comments

Comments
 (0)