Skip to content

Commit

Permalink
use requestAnimationFrame for accurate perf priors
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshaf committed Nov 23, 2024
1 parent 5cd2d70 commit 158fcf1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/idb-cache-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ const App = () => {
const end1 = performance.now();
setTimeToGenerate(end1 - start1);

// for accurate perf measurement
await new Promise((resolve) => requestAnimationFrame(resolve));

const start2 = performance.now();

for (let i = 0; i < DEFAULT_NUM_ITEMS; i++) {
Expand All @@ -188,6 +191,9 @@ const App = () => {
}

try {
// for accurate perf measurement
await new Promise((resolve) => requestAnimationFrame(resolve));

const results: Array<string | null> = [];
const start = performance.now();

Expand Down Expand Up @@ -216,6 +222,9 @@ const App = () => {
}

try {
// for accurate perf measurement
await new Promise((resolve) => requestAnimationFrame(resolve));

const start = performance.now();
await cache.cleanup();
const end = performance.now();
Expand All @@ -233,6 +242,9 @@ const App = () => {
}

try {
// for accurate perf measurement
await new Promise((resolve) => requestAnimationFrame(resolve));

const start = performance.now();
const count = await cache.count();
const end = performance.now();
Expand All @@ -251,6 +263,9 @@ const App = () => {
}

try {
// for accurate perf measurement
await new Promise((resolve) => requestAnimationFrame(resolve));

const start = performance.now();
await cache.clear();
localStorage.removeItem("keyCounter");
Expand Down

0 comments on commit 158fcf1

Please sign in to comment.