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
gemma2:9b
, generated one year ago):
This benchmark tests the performance of retrieving values from localStorage using JavaScript's `localStorage.getItem()` method. **Options Compared:** The benchmark presents two nearly identical test cases: "getItem 1" and "getItem 2". The only difference is their name. Both cases perform the same operation: 1. Retrieve various data items (token, role, userId, companyId, userName, userEmail) stored in localStorage using `localStorage.getItem()`. 2. For 'userId' and 'companyId', they use `parseInt()` to convert the retrieved values from strings to numbers. They also utilize the `|| ''` operator to handle potential cases where a value is missing, ensuring the parsing doesn't throw an error. **Pros/Cons:** - **Minimal Variation:** The minimal difference between test cases limits the ability to discern significant performance variations due to factors other than `localStorage.getItem()` itself. - **Single Operation Focus:** The tests isolate the retrieval operation, avoiding extraneous code that could influence results. **Consideration:** To make this benchmark more informative, you'd want to: * **Vary Retrieval Patterns:** Test different combinations of items retrieved at once (e.g., retrieving all items vs. individual items). * **Introduce Different Data Sizes:** Store varying amounts of data in localStorage to see how retrieval performance scales with dataset size. * **Explore Alternative Storage Mechanisms:** Compare `localStorage` performance to other storage options like IndexedDB or in-memory data structures. **Alternatives:** * **IndexedDB:** A more robust database built into browsers, suitable for larger datasets and more complex operations than `localStorage`. * **SessionStorage:** Similar to `localStorage`, but data is cleared when the browser tab is closed. Useful for temporary data storage. * **In-Memory Data Structures (Arrays, Objects):** Offer fast access times but are volatile (data is lost when the script ends). Let me know if you have any more questions about this benchmark or need further clarification on any aspect!
Related benchmarks:
localStorage and sessionStorage Speedtest
localStorage and sessionStorage Speedtest2
aaaabbb
aaaabbbnmmbhjhg
Comments
Confirm delete:
Do you really want to delete benchmark?