class CustomMapWithOwnProperty {
constructor(size) {
this.count = 0;
this.size = size;
this.data = {};
}
getValue(key) {
return this.data.hasOwnProperty(key) ? this.data[key] : null;
}
setValue(key, value) {
if (this.count > this.size) {
throw new RangeError('exceeded map size of', this.size);
}
this.data[key] = value;
this.count++;
}
}
class CustomFastMap {
constructor(size) {
this.count = 0;
this.size = size;
this.data = {};
}
getValue(key) {
return this.data[key] || null;
}
setValue(key, value) {
if (this.count > this.size) {
throw new RangeError('exceeded map size of', this.size);
}
this.data[key] = value;
this.count++;
}
}
const es6Map256 = new Map();
const es6Map1024 = new Map();
const es6Map2048 = new Map();
const customMapWithOwnProperty256 = new CustomMapWithOwnProperty(256);
const customMapWithOwnProperty1024 = new CustomMapWithOwnProperty(1024);
const customMapWithOwnProperty2048 = new CustomMapWithOwnProperty(2056);
const customFastMap256 = new CustomFastMap(256);
const customFastMap1024 = new CustomFastMap(1024);
const customFastMap2048 = new CustomFastMap(2048);
for (let i = 0; i < 256; i++) {
es6Map256.set('key-' + i, i);
customMapWithOwnProperty256.setValue('key-' + i, i);
customFastMap256.setValue('key-' + i, i);
}
for (let i = 0; i < 1024; i++) {
es6Map1024.set('key-' + i, i);
customMapWithOwnProperty1024.setValue('key-' + i, i);
customFastMap1024.setValue('key-' + i, i);
}
for (let i = 0; i < 2048; i++) {
es6Map2048.set('key-' + i, i);
customMapWithOwnProperty2048.setValue('key-' + i, i);
customFastMap2048.setValue('key-' + i, i);
}