Skip to content

Commit

Permalink
🧪 add performance test for queueTask()
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Feb 6, 2024
1 parent eae99c8 commit f965cf2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions playground/playground.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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<void>((resolve) => queueTask(resolve))
count++
}
console.log(count.toString(), '→ queueTask()')
}
{
const start = performance.now()
Expand All @@ -139,6 +154,6 @@ async function postTaskVsYieldOrContinue() {
await yieldOrContinue('smooth')
count++
}
console.log('count', count)
console.log(count.toString(), '→ yieldOrContinue()')
}
}

0 comments on commit f965cf2

Please sign in to comment.