Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
benchmark: add more options to map-bench
  • Loading branch information
TimothyGu committed Mar 22, 2017
commit 6fd9a9939e37655793b77b982d12e0581c8fdcf9
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