Skip to content

Commit

Permalink
add benchmark for arraybuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
gr0uch committed Oct 11, 2021
1 parent 48b0d30 commit d5ead26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/demo3.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
worker.postMessage(["setMany", people]);
worker.onmessage = resolve;
});
document.write('<pre>write bulk ' + (Date.now() - time) + ' ms</pre>');
document.write('<pre>write bulk (worker) ' + (Date.now() - time) + ' ms</pre>');
time = Date.now();
const result = await new Promise((resolve) => {
worker.postMessage(["getMany", ids]);
worker.onmessage = ({ data }) => resolve(data);
});
document.write('<pre>read bulk ' + (Date.now() - time) + ' ms</pre>');
document.write('<pre>read bulk (worker) ' + (Date.now() - time) + ' ms</pre>');
time = Date.now();
</script>
25 changes: 25 additions & 0 deletions test/demo4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IndexedDB demo</title>
<script type="module">
import { setMany, getMany } from 'https://cdn.jsdelivr.net/npm/idb-keyval@6/+esm';
const enc = new TextEncoder();
let time;
const people = new Array(100).fill().map(() => {
const id = Math.random();
return [id, enc.encode(JSON.stringify({
id,
name: 'B',
friends: [ 1 ],
})).buffer];
})

time = Date.now();
await setMany(people);
document.write('<pre>write bulk (ArrayBuffer) ' + (Date.now() - time) + ' ms</pre>');
time = Date.now();

await getMany(people.map(([id]) => id));
document.write('<pre>read bulk (ArrayBuffer) ' + (Date.now() - time) + ' ms</pre>');
time = Date.now();
</script>

0 comments on commit d5ead26

Please sign in to comment.