Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
localStorage and sessionStorage Speedtest
(version: 0)
Comparing performance of:
Control vs localStorage vs sessionStorage
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
localStorage.setItem('foo', 'bar') sessionStorage.setItem('foo', 'bar')
Tests:
Control
var FOO = 'bar';
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 month ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Control
113962608.0 Ops/sec
localStorage
3827744.0 Ops/sec
sessionStorage
3854723.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON data and explain what's being tested in each test case. **Benchmark Definition** The `Script Preparation Code` section defines a simple benchmark that sets two values using JavaScript: one stored in local storage (`localStorage`) and another stored in session storage (`sessionStorage`). The goal is to measure the performance difference between accessing these two types of storage. **Options Compared** Three options are being compared: 1. **Control**: This test case serves as a baseline, with no storage-related code executed. 2. **localStorage**: This test case accesses the value stored in local storage using `localStorage.getItem('foo')`. 3. **sessionStorage**: This test case accesses the value stored in session storage using `sessionStorage.getItem('foo')`. **Pros and Cons of Each Approach** * **Control**: As a baseline, it provides a reference point for the performance of each test case. However, since no code is executed, its results might not accurately represent the performance differences between local and session storage. * **localStorage**: This approach requires loading the value from local storage, which can be slower due to disk I/O and caching considerations. On the other hand, local storage values are typically persisted even after the script finishes execution, making it a useful feature for storing data that needs to be retained between page loads or sessions. * **sessionStorage**: Similar to local storage, accessing a value from session storage requires loading it from memory, which can be slower than accessing in-memory variables. However, since session storage values are typically cleared when the session ends (i.e., when the user navigates away from the page), this approach might not provide accurate results for benchmarking purposes. **Library and Purpose** In all three test cases, JavaScript's built-in `localStorage` and `sessionStorage` APIs are used to interact with these storage mechanisms. These APIs provide a convenient way to store and retrieve data in a browser environment, allowing developers to implement features like storing user preferences or cached data. **Special JS Feature/Syntax (Not Applicable)** There is no special JavaScript feature or syntax being tested in this benchmark. The focus is solely on the performance difference between accessing local storage and session storage values. **Other Alternatives** If you wanted to compare different approaches for accessing storage, you might consider alternative methods, such as: * Using a third-party library like ` IndexedDB` (a more advanced key-value store that provides better performance than local storage) or `WebStorage` libraries. * Implementing custom storage solutions using HTML5 Web Storage APIs, like storing data in cookies or using a custom server-side API to store and retrieve data. Keep in mind that these alternative approaches might require additional infrastructure or modifications to your codebase. The built-in `localStorage` and `sessionStorage` APIs are often sufficient for most use cases, but may not provide the best performance or scalability when dealing with large datasets or high-traffic applications.
Related benchmarks:
localStorage vs sessionStorage vs Reading a Hardcoded Array Speedtest
Just localStorage vs sessionStorage Speedtest
localStorage and sessionStorage Speedtest2
In-memory, localStorage and sessionStorage Speedtest
Comments
Confirm delete:
Do you really want to delete benchmark?