Skip to content

Commit

Permalink
benchmark: add more options to map-bench
Browse files Browse the repository at this point in the history
PR-URL: #11930
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
TimothyGu committed Mar 24, 2017
1 parent d9b0e4c commit a6e69f8
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion benchmark/es/map-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const common = require('../common.js');
const assert = require('assert');

const bench = common.createBenchmark(main, {
method: ['object', 'nullProtoObject', 'fakeMap', 'map'],
method: [
'object', 'nullProtoObject', 'nullProtoLiteralObject', 'storageObject',
'fakeMap', 'map'
],
millions: [1]
});

Expand Down Expand Up @@ -36,6 +39,37 @@ function runNullProtoObject(n) {
bench.end(n / 1e6);
}

function runNullProtoLiteralObject(n) {
const m = { __proto__: null };
var i = 0;
bench.start();
for (; i < n; i++) {
m['i' + i] = i;
m['s' + i] = String(i);
assert.strictEqual(String(m['i' + i]), m['s' + i]);
m['i' + i] = undefined;
m['s' + i] = undefined;
}
bench.end(n / 1e6);
}

function StorageObject() {}
StorageObject.prototype = Object.create(null);

function runStorageObject(n) {
const m = new StorageObject();
var i = 0;
bench.start();
for (; i < n; i++) {
m['i' + i] = i;
m['s' + i] = String(i);
assert.strictEqual(String(m['i' + i]), m['s' + i]);
m['i' + i] = undefined;
m['s' + i] = undefined;
}
bench.end(n / 1e6);
}

function fakeMap() {
const m = {};
return {
Expand Down Expand Up @@ -84,6 +118,12 @@ function main(conf) {
case 'nullProtoObject':
runNullProtoObject(n);
break;
case 'nullProtoLiteralObject':
runNullProtoLiteralObject(n);
break;
case 'storageObject':
runStorageObject(n);
break;
case 'fakeMap':
runFakeMap(n);
break;
Expand Down

0 comments on commit a6e69f8

Please sign in to comment.