Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Storage Perf 2
(version: 0)
Comparing performance of:
Session Storage vs Local Storage vs Cookie Storage
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } setCookie('fdsfs', 'fdsfs'); sessionStorage.setItem('fdsfs', 'fdsfs'); localStorage.setItem('fdsfs', 'fdsfs');
Tests:
Session Storage
sessionStorage.getItem('fdsfs');
Local Storage
localStorage.getItem('fdsfs');
Cookie Storage
const getCookie = (name) => ( document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || '' ) getCookie(document.cookie, 'fdsfs');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Session Storage
Local Storage
Cookie Storage
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):
**Overview of the Benchmark** The provided JSON represents a JavaScript microbenchmark for testing the performance of different storage mechanisms: session storage, local storage, and cookie storage. **Options Compared** Three options are compared: 1. **Session Storage**: Retrieves a value from `sessionStorage` using `getItem('fdsfs')`. 2. **Local Storage**: Retrieves a value from `localStorage` using `getItem('fdsfs')`. 3. **Cookie Storage**: Uses a custom function to parse the cookie string and retrieve the value of 'fdsfs'. **Pros and Cons of Each Approach** 1. **Session Storage**: * Pros: Fast, lightweight, and easy to use. * Cons: Values are lost when the session is closed (e.g., when the tab is closed). 2. **Local Storage**: * Pros: More persistent than session storage, values can be stored for a longer period. * Cons: Can be slower due to the overhead of storing and retrieving data in local storage. 3. **Cookie Storage**: * Pros: Provides more control over the storage mechanism and allows for custom parsing. * Cons: Requires manual management of cookies, which can add complexity. **Library and Purpose** None of the test cases use a library. However, it's worth noting that `sessionStorage` and `localStorage` are built-in DOM APIs in modern browsers, making them widely supported. **Special JS Feature or Syntax** No special JavaScript features or syntax are used in these benchmark tests. **Other Alternatives** If you were to write similar benchmarks for other storage mechanisms, you might consider: 1. **IndexedDB**: A more advanced key-value store that provides better performance and persistence than local storage. 2. **WebStorage APIs with custom implementations**: You could create your own implementation of web storage using JavaScript, which would allow for greater customization and control over the storage mechanism. Overall, this benchmark test provides a simple and effective way to compare the performance of different storage mechanisms in JavaScript, making it easy for developers to evaluate their choices based on real-world data.
Related benchmarks:
localStorage and sessionStorage Speedtest
Storage Perf
,mcv,bmcvbm
localStorage and sessionStorage Speedtest2
Comments
Confirm delete:
Do you really want to delete benchmark?