localStorage.setItem('foo', 'bar')
sessionStorage.setItem('foo', 'bar')
var ARR = ['bar'];
var FOO = 'bar';
var FOO = localStorage.getItem('foo');
var FOO = sessionStorage.getItem('foo');
var FOO = ARR[Math.floor(Math.random() * ARR.length)]
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Control | |
localStorage | |
sessionStorage | |
Read Array |
Test name | Executions per second |
---|---|
Control | 230526128.0 Ops/sec |
localStorage | 9649553.0 Ops/sec |
sessionStorage | 9604024.0 Ops/sec |
Read Array | 118574384.0 Ops/sec |
Let's break down the benchmark and explain what is being tested.
Benchmark Definition
The website measures JavaScript performance in various scenarios, including comparing different storage options (localStorage, sessionStorage) and accessing an array of values.
Options Compared
Three main options are compared:
Pros and Cons
Library Usage
The test cases use two libraries:
Special JS Features or Syntax
The test cases use some special syntax:
var ARR = ['bar'];
) to define an array of values.Math.random()
to generate a random index for accessing the array.Other Considerations
When using local storage or session storage, it's essential to consider data sizes and types, as they can impact performance. Additionally, some browsers might have specific settings or configurations that affect local storage and session storage performance.
Alternatives
If you need to compare different storage options or accessing arrays, here are some alternative approaches: