mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
96ec7eede9
PR-URL: https://github.com/nodejs/node/pull/55040 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
'use strict';
|
|
const { join } = require('node:path');
|
|
const common = require('../common.js');
|
|
const tmpdir = require('../../test/common/tmpdir');
|
|
|
|
let cnt = 0;
|
|
|
|
tmpdir.refresh();
|
|
|
|
function nextLocalStorage() {
|
|
return join(tmpdir.path, `${++cnt}.localstorage`);
|
|
}
|
|
|
|
const options = {
|
|
flags: ['--experimental-webstorage', `--localstorage-file=${nextLocalStorage()}`],
|
|
};
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
type: ['localStorage-setItem',
|
|
'localStorage-setter',
|
|
'sessionStorage-setItem',
|
|
'sessionStorage-setter'],
|
|
// Note: web storage has only 10mb quota
|
|
n: [1e5],
|
|
}, options);
|
|
|
|
function main({ n, type }) {
|
|
const localStorage = globalThis.localStorage;
|
|
const sessionStorage = globalThis.sessionStorage;
|
|
|
|
switch (type) {
|
|
case 'localStorage-setItem':
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
localStorage.setItem(i, i);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'localStorage-setter':
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
localStorage[i] = i;
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'sessionStorage-setItem':
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
sessionStorage.setItem(i, i);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'sessionStorage-setter':
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
sessionStorage[i] = i;
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
default:
|
|
new Error('Invalid type');
|
|
}
|
|
}
|