Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Local storage vs memory
(version: 0)
Comparing performance of:
Local Storage vs In Memory
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.localStorage.setItem("data", '{"attributes.support_case_state":{"type":"string_or_null_array","value":["open"]},"attributes.tier":{"type":"string_or_null_array","value":["tier_1"]},"attributes.user_persona":{"type":"string_or_null_array","value":["rider"]},"attributes.country_code":{"type":"string_or_null_array","value":["az"]},"attributes.city_id":{"type":"number_or_null_array","value":[211]},"attributes.safety_severity_level":{"type":"string_or_null_array","value":["minor"]}}'); var memoryData = JSON.parse('{"attributes.support_case_state":{"type":"string_or_null_array","value":["open"]},"attributes.tier":{"type":"string_or_null_array","value":["tier_1"]},"attributes.user_persona":{"type":"string_or_null_array","value":["rider"]},"attributes.country_code":{"type":"string_or_null_array","value":["az"]},"attributes.city_id":{"type":"number_or_null_array","value":[211]},"attributes.safety_severity_level":{"type":"string_or_null_array","value":["minor"]}}');
Tests:
Local Storage
Object.fromEntries(Object.entries(JSON.parse(window.localStorage.getItem("data"))).map((key, value) => [key, value]));
In Memory
Object.fromEntries(Object.entries(memoryData).map((key, value) => [key, value]));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Local Storage
In Memory
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 OPR/119.0.0.0
Browser/OS:
Opera 119 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Local Storage
449374.5 Ops/sec
In Memory
762641.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided benchmark measures the performance difference between using Local Storage and in-memory data structures to store and retrieve objects. **Options Compared** Two options are compared: 1. **Local Storage**: Uses Web Storage API, specifically `localStorage`, to store and retrieve objects as JSON strings. 2. **In-Memory**: Uses JavaScript's built-in object data structure to store and retrieve objects. **Pros and Cons of Each Approach** ### Local Storage Pros: * **Persistent storage**: Data is stored even after the tab is closed or the browser restarts. * Easy to implement, as it leverages a standard API. Cons: * **Slow access times**: Accessing data in `localStorage` can be slower due to network latency and storage constraints. * Limited capacity (5MB). ### In-Memory Pros: * **Fast access times**: Data is readily available without any additional overhead. * No storage limits or latency concerns. Cons: * **Session-based storage**: Data is lost when the tab is closed or the browser restarts. * Requires manual implementation of data structures and serialization. **Library Used** In this benchmark, the `JSON.parse()` function from JavaScript's built-in API is used to parse JSON strings stored in Local Storage. Additionally, the `Object.fromEntries()` function (available in modern browsers) is used to create objects from arrays. **Special JS Feature/Syntax** The `Object.entries()` and `Object.fromEntries()` methods are used, which are part of the ECMAScript 2020 standard. These methods provide a convenient way to work with object entries and create objects from iterables. **Other Alternatives** If you're interested in exploring other alternatives: * **IndexedDB**: A more advanced storage solution that provides better performance and capacity than Local Storage. * **Web SQL Database**: Another API for storing data in the browser, which offers more advanced features than Local Storage. * **Custom data structures**: You can implement custom data structures, such as hash tables or binary search trees, to optimize performance. Keep in mind that these alternatives may require more complex implementation and might not be suitable for all use cases.
Related benchmarks:
LocalStorage Write with JSON.stringify v2
Memory vs Local vs Session
aaaabbb
aaaabbbnmmbhjhg
Comments
Confirm delete:
Do you really want to delete benchmark?