Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
localStorage vs Reading a Hardcoded Array Speedtest
(version: 0)
Comparing performance of:
localStorage vs sessionStorage vs Read Array
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
localStorage.setItem('foo', 'bar') sessionStorage.setItem('foo', 'bar') var ARR = ['bar'];
Tests:
localStorage
var FOO = localStorage.getItem('foo');
sessionStorage
var FOO = sessionStorage.getItem('foo');
Read Array
var FOO = ARR[Math.floor(Math.random() * ARR.length)]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
localStorage
sessionStorage
Read Array
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net. **What is being tested?** MeasureThat.net provides a platform for users to create and run JavaScript microbenchmarks, which are small scripts that measure the execution time of specific pieces of code. In this case, we have three test cases: 1. **`localStorage`**: This test case measures the time it takes to retrieve data from `localStorage`. 2. **`sessionStorage`**: Similar to the first one, but for `sessionStorage`, which is another type of local storage that can only be accessed during a user's session. 3. **`Read Array`**: This test case measures the time it takes to access an array using indexing (e.g., `arr[0]`) or randomness (e.g., `Math.random() * arr.length`). The purpose is to compare the performance of accessing an array versus retrieving data from local storage. **Options compared** The options being compared are: * Accessing data from `localStorage` vs. a hardcoded array * Accessing data from `sessionStorage` These two options are being compared because they serve different purposes and have different characteristics: * **`localStorage`**: Data is stored locally on the client-side, and it persists across page reloads and user sessions. * **Hardcoded Array**: A simple array defined in the script, which does not store any data persistently. **Pros and Cons** Here are some pros and cons of each approach: * **`localStorage`**: + Pros: Easy to use, fast access times, and it's a standard feature in modern browsers. + Cons: Data is only accessible during the user's session, and it can lead to performance issues if not properly optimized. * **Hardcoded Array**: + Pros: Fast access times, predictable behavior, and no dependence on external storage. + Cons: Data is not persistent across page reloads or user sessions. **Library** There isn't a specific library being used in this benchmark. However, the use of `localStorage` and `sessionStorage` implies that the browser's built-in local storage API is being utilized. **Special JS feature or syntax** None are mentioned specifically for this benchmark. **Other alternatives** If you wanted to modify this benchmark, you could consider adding additional test cases, such as: * Accessing data from `sessionStorage` with different access patterns (e.g., accessing a specific key multiple times) * Using different types of local storage (e.g., `IndexedDB`) * Comparing the performance of accessing an array using different indexing methods (e.g., `arr[0]`, `arr[Math.floor(Math.random() * arr.length)]`) Keep in mind that these modifications would require updating the benchmark definition and script preparation code to accommodate the new test cases.
Related benchmarks:
push vs. Index write performance
Array constructor vs literal performance, 12345
Push vs Spread JavaScript
Array add vs .unshift()
Array.Prototype.at vs index
Comments
Confirm delete:
Do you really want to delete benchmark?