-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #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>
- Loading branch information
1 parent
c4681d5
commit 96ec7ee
Showing
3 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'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-getItem', | ||
'localStorage-getter', | ||
'sessionStorage-getItem', | ||
'sessionStorage-getter'], | ||
// Note: web storage has only 10mb quota | ||
n: [1e5], | ||
}, options); | ||
|
||
function fillStorage(storage, n) { | ||
for (let i = 0; i < n; i++) { | ||
storage.setItem(i, i); | ||
} | ||
} | ||
|
||
function main({ n, type }) { | ||
const localStorage = globalThis.localStorage; | ||
const sessionStorage = globalThis.sessionStorage; | ||
|
||
switch (type) { | ||
case 'localStorage-getItem': | ||
fillStorage(localStorage, n); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
localStorage.getItem(i); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'localStorage-getter': | ||
fillStorage(localStorage, n); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
// eslint-disable-next-line no-unused-expressions | ||
localStorage[i]; | ||
} | ||
bench.end(n); | ||
break; | ||
case 'sessionStorage-getItem': | ||
fillStorage(sessionStorage, n); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
sessionStorage.getItem(i); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'sessionStorage-getter': | ||
fillStorage(sessionStorage, n); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
// eslint-disable-next-line no-unused-expressions | ||
sessionStorage[i]; | ||
} | ||
bench.end(n); | ||
break; | ||
default: | ||
new Error('Invalid type'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'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-removeItem', | ||
'localStorage-delete', | ||
'sessionStorage-removeItem', | ||
'sessionStorage-delete', | ||
], | ||
// Note: web storage has only 10mb quota | ||
n: [1e5], | ||
}, options); | ||
|
||
function fillStorage(storage, n) { | ||
for (let i = 0; i < n; i++) { | ||
storage.setItem(i, i); | ||
} | ||
} | ||
|
||
function main({ n, type }) { | ||
const localStorage = globalThis.localStorage; | ||
const sessionStorage = globalThis.sessionStorage; | ||
|
||
switch (type) { | ||
case 'localStorage-removeItem': | ||
fillStorage(localStorage, n); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
localStorage.removeItem(i); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'localStorage-delete': | ||
fillStorage(localStorage, n); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
delete localStorage[i]; | ||
} | ||
bench.end(n); | ||
break; | ||
case 'sessionStorage-removeItem': | ||
fillStorage(sessionStorage, n); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
sessionStorage.removeItem(i); | ||
} | ||
bench.end(n); | ||
break; | ||
|
||
case 'sessionStorage-delete': | ||
fillStorage(localStorage, n); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
delete sessionStorage[i]; | ||
} | ||
bench.end(n); | ||
break; | ||
default: | ||
new Error('Invalid type'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'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'); | ||
} | ||
} |