Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
localStorage.getItem
(version: 0)
Comparing performance of:
getItem 1 vs getItem 2
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
localStorage.setItem('token', '1'); localStorage.setItem('role', '1'); localStorage.setItem('userId', '1'); localStorage.setItem('companyId', '1'); localStorage.setItem('userName', '1'); localStorage.setItem('userEmail', '1');
Tests:
getItem 1
const token = localStorage.getItem('token'); const role = localStorage.getItem('role'); const userId = parseInt(localStorage.getItem('userId') || '', 10); const companyId = parseInt(localStorage.getItem('companyId') || '', 10); const userName = localStorage.getItem('userName'); const userEmail = localStorage.getItem('userEmail');
getItem 2
const token = localStorage.getItem('token'); const role = localStorage.getItem('role'); const userId = parseInt(localStorage.getItem('userId') || '', 10); const companyId = parseInt(localStorage.getItem('companyId') || '', 10); const userName = localStorage.getItem('userName'); const userEmail = localStorage.getItem('userEmail');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
getItem 1
getItem 2
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/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
getItem 1
202047.8 Ops/sec
getItem 2
197757.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's dive into the details of this benchmark. **What is being tested?** The benchmark is testing how quickly JavaScript can retrieve values from `localStorage` using the `localStorage.getItem()` method. **Options compared** There are two test cases, "getItem 1" and "getItem 2", which use the same code snippet to retrieve six different values from `localStorage`. The only difference between the two tests is that "getItem 2" uses the exact same code as "getItem 1". In other words, this benchmark is essentially testing whether running the same JavaScript code multiple times makes any significant difference in terms of performance. **Pros and cons** One possible pro of reusing the same code snippet across multiple test cases is that it allows for more efficient benchmarking, since only one version of the code needs to be prepared. However, this approach may not accurately represent real-world scenarios where different use cases might involve varying amounts of code execution. As for cons, running the same code repeatedly without any meaningful changes between tests might lead to misleading results, as the performance improvements or degradations observed could be due to various factors unrelated to the actual benchmarked functionality (e.g., caching effects, optimization by the browser). **Other considerations** * **Cache effect**: The test cases set several values in `localStorage` before retrieving them. This might influence the results, as some browsers might cache these values, potentially leading to faster retrieval times. * **Parsing integers**: In both test cases, the `userId` and `companyId` values are parsed as integers using `parseInt()`. However, this is not necessary for `getItem()` method, which returns a string. This might be an optimization attempt or a reflection of specific use case requirements. **Library used** None in this example. **JS feature or syntax** None specifically relevant to this benchmark. The code uses standard JavaScript and DOM APIs. **Alternatives** To better represent real-world scenarios, alternative benchmarks could include: * Testing retrieval from `localStorage` with varying amounts of data (e.g., more values stored). * Comparing performance between different `localStorage.getItem()` usage patterns. * Incorporating diverse input types (e.g., retrieving non-string values) to see how the browser handles them. These modifications would provide a more comprehensive understanding of the performance implications when working with `localStorage`.
Related benchmarks:
localStorage and sessionStorage Speedtest
localStorage and sessionStorage Speedtest2
aaaabbb
aaaabbbnmmbhjhg
Comments
Confirm delete:
Do you really want to delete benchmark?