From f965cf2311279cdba1149a060a9cb0d50567d6eb Mon Sep 17 00:00:00 2001 From: Antonio Stoilkov Date: Tue, 6 Feb 2024 09:35:12 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20add=20performance=20test=20for?= =?UTF-8?q?=20queueTask()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/playground.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/playground/playground.ts b/playground/playground.ts index e78019e..551b1ac 100644 --- a/playground/playground.ts +++ b/playground/playground.ts @@ -1,4 +1,10 @@ -import { isTimeToYield, SchedulingStrategy, withResolvers, yieldOrContinue } from '../index' +import { + isTimeToYield, + queueTask, + SchedulingStrategy, + withResolvers, + yieldOrContinue, +} from '../index' document.querySelector('#run-interactive')!.addEventListener('click', () => { run('interactive') @@ -130,7 +136,16 @@ async function postTaskVsYieldOrContinue() { await postTask() count++ } - console.log('count', count) + console.log(count.toString(), '→ postTask()') + } + { + const start = performance.now() + let count = 0 + while (performance.now() - start < 1000) { + await new Promise((resolve) => queueTask(resolve)) + count++ + } + console.log(count.toString(), '→ queueTask()') } { const start = performance.now() @@ -139,6 +154,6 @@ async function postTaskVsYieldOrContinue() { await yieldOrContinue('smooth') count++ } - console.log('count', count) + console.log(count.toString(), '→ yieldOrContinue()') } }