Skip to content

Commit 158fcf1

Browse files
committed
use requestAnimationFrame for accurate perf priors
1 parent 5cd2d70 commit 158fcf1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/idb-cache-app/src/App.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ const App = () => {
165165
const end1 = performance.now();
166166
setTimeToGenerate(end1 - start1);
167167

168+
// for accurate perf measurement
169+
await new Promise((resolve) => requestAnimationFrame(resolve));
170+
168171
const start2 = performance.now();
169172

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

190193
try {
194+
// for accurate perf measurement
195+
await new Promise((resolve) => requestAnimationFrame(resolve));
196+
191197
const results: Array<string | null> = [];
192198
const start = performance.now();
193199

@@ -216,6 +222,9 @@ const App = () => {
216222
}
217223

218224
try {
225+
// for accurate perf measurement
226+
await new Promise((resolve) => requestAnimationFrame(resolve));
227+
219228
const start = performance.now();
220229
await cache.cleanup();
221230
const end = performance.now();
@@ -233,6 +242,9 @@ const App = () => {
233242
}
234243

235244
try {
245+
// for accurate perf measurement
246+
await new Promise((resolve) => requestAnimationFrame(resolve));
247+
236248
const start = performance.now();
237249
const count = await cache.count();
238250
const end = performance.now();
@@ -251,6 +263,9 @@ const App = () => {
251263
}
252264

253265
try {
266+
// for accurate perf measurement
267+
await new Promise((resolve) => requestAnimationFrame(resolve));
268+
254269
const start = performance.now();
255270
await cache.clear();
256271
localStorage.removeItem("keyCounter");

0 commit comments

Comments
 (0)