Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
In-memory, localStorage and sessionStorage Speedtest
(version: 0)
Comparing performance of:
Control vs localStorage vs sessionStorage
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
localStorage.setItem('foo', 'bar') sessionStorage.setItem('foo', 'bar') window.foo = 'bar';
Tests:
Control
var FOO = window.foo
localStorage
var FOO = localStorage.getItem('foo');
sessionStorage
var FOO = sessionStorage.getItem('foo');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Control
localStorage
sessionStorage
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Control
115676632.0 Ops/sec
localStorage
3909512.0 Ops/sec
sessionStorage
3871616.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks and MeasureThat.net. **What is being tested?** The benchmark tests the speed of accessing variables in different storage mechanisms: local storage (`localStorage`), session storage (`sessionStorage`), and global scope (`window.foo`). The goal is to measure how quickly a script can access a variable that has been previously set using one of these methods. **Options compared** There are three options being compared: 1. **Global Scope (Window.Foo)**: This option tests accessing the variable through the `window` object, which is the global scope in JavaScript. 2. **localStorage**: This option tests accessing the variable by retrieving it from local storage using the `getItem()` method. 3. **sessionStorage**: This option tests accessing the variable by retrieving it from session storage using the `getItem()` method. **Pros and Cons** * **Global Scope (Window.Foo)**: + Pros: Fastest access time, as it doesn't require any additional storage lookups. + Cons: Not suitable for scenarios where variables need to be stored persistently across sessions or page reloads. * **localStorage**: + Pros: Suitable for storing data that needs to be persisted across sessions and page reloads. + Cons: Slower access time compared to global scope, as it requires a storage lookup. * **sessionStorage**: + Pros: Similar to `localStorage`, but data is cleared when the session ends (i.e., when the page is closed or navigation happens). + Cons: Faster access time than `localStorage` due to similar caching mechanisms. **Library and Purpose** The benchmark uses the following libraries: * None explicitly mentioned in the provided code. However, it's worth noting that the script preparation code involves setting an item in local storage (`localStorage.setItem('foo', 'bar')`) and session storage (`sessionStorage.setItem('foo', 'bar')`). These are part of the Web Storage API, which is a built-in JavaScript API. **Special JS Features or Syntax** There are no special JS features or syntax explicitly used in this benchmark. However, it's worth noting that local storage and session storage rely on the concept of "scope" in JavaScript, which determines the visibility and accessibility of variables. **Other Alternatives** If you're interested in comparing other options, here are some alternatives: * **IndexedDB**: A client-side storage mechanism that provides a more structured and queryable storage system compared to local storage and session storage. * **WebStorage alternatives (e.g., Cache API)**: Other web storage mechanisms like the Cache API or IndexedDB-like APIs might be used in specific scenarios, but they are not directly related to this benchmark. In summary, this benchmark tests the speed of accessing variables in different storage mechanisms: global scope, local storage, and session storage. Each option has its pros and cons, with global scope being the fastest but lacking persistence, while local storage and session storage offer persistence but slower access times.
Related benchmarks:
localStorage and sessionStorage Speedtest
localStorage vs sessionStorage vs Reading a Hardcoded Array Speedtest
Just localStorage vs sessionStorage Speedtest
2nd localStorage and sessionStorage Speedtest
Comments
Confirm delete:
Do you really want to delete benchmark?