localStorage vs. Objects
JavaScript performance comparison
Info
Tests the difference between reading from localStorage as compared to reading data from an object.
Preparation code
<script>
localStorage.setItem("foo", "body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }");
var FOO = {
foo: "body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }"
};
var value;
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Reading from an object |
|
pending… |
Reading from localStorage getItem |
|
pending… |
Reading from localStorage index |
|
pending… |
Reading from localStorage property |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Nicholas C. Zakas
- Revision 2: published
- Revision 3: published
- Revision 4: published by Morgan Cheng
- Revision 6: published by Ben Voran
- Revision 7: published by Ben Voran
- Revision 8: published by Ben Voran
- Revision 10: published by Bram Stein
- Revision 11: published by jurby
- Revision 13: published
- Revision 14: published
- Revision 16: published by Asim
- Revision 17: published
- Revision 19: published by Nicholas C. Zakas
- Revision 20: published by Sebastiaan
- Revision 21: published
- Revision 22: published
- Revision 23: published
- Revision 25: published by women
- Revision 26: published by Rod Knowlton
- Revision 27: published
- Revision 29: published
- Revision 30: published
3 comments
This is like testing whether it's faster to access object in memory or retrieve it from harddrive. I wonder which one is faster...
wonder why IE9 crashes on this page, would be interesting too. Also some times are just weird (Android 2.1<2.2>2.3)?!
@James, that is exactly what it is.