Skip to content

Instantly share code, notes, and snippets.

@nkt
Created April 14, 2016 11:03
Show Gist options
  • Save nkt/378b41cb6e9aa84d10ab74e6996bd2be to your computer and use it in GitHub Desktop.
Save nkt/378b41cb6e9aa84d10ab74e6996bd2be to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function testLocalStorage() {
for (var i = 0; i < 1000; i++) {
localStorage.setItem(i, i);
}
var result = [];
for (var i = 0; i < 1000; i++) {
result.push(localStorage.getItem(i));
}
return result;
}
function clearLocalStorage() {
localStorage.clear();
}
function benchmark(name, callback, clear) {
for (var i = 0; i < 10; i++) {
callback();
clear();
}
console.time(name);
callback();
console.timeEnd(name);
}
benchmark('localStorage', testLocalStorage, clearLocalStorage);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment