Skip to content

Commit

Permalink
🧪 improve playground
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Feb 12, 2024
1 parent db0c4c1 commit ab7a52f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</head>
<body>
<div>
<code>main-thread-scheduling:</code>
<button id="run-interactive">interactive</button>
<button id="run-interactive-5s">interactive (5s)</button>
<button id="run-smooth">smooth</button>
Expand All @@ -44,12 +45,14 @@
</div>
<br />
<div>
<code>scheduler.postTask():</code>
<button id="post-task-blocking">postTask('user-blocking')</button>
<button id="post-task-visible">postTask('user-visible')</button>
<button id="post-task-background">postTask('background')</button>
</div>
<br />
<div>
<code>others:</code>
<button id="queue-task">queueTask()</button>
<button id="simulate-work">simulateWork()</button>
<button id="post-task-vs-yield-or-continue">postTask() vs yieldOrContinue()</button>
Expand Down
9 changes: 4 additions & 5 deletions playground/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ document.querySelector('#queue-task')!.addEventListener('click', () => {
})

async function run(strategy: SchedulingStrategy, time: number = 1000) {
const start = Date.now()
while (Date.now() - start < time) {
const start = performance.now()
while (performance.now() - start < time) {
if (isTimeToYield(strategy)) {
await yieldOrContinue(strategy)
}
simulateWork()
}
performance.measure(strategy, {
performance.measure(`${strategy} (${Math.round(time / 1000)}s)`, {
start: start,
end: Date.now(),
detail: 'awesome',
end: performance.now(),
})
}

Expand Down

0 comments on commit ab7a52f

Please sign in to comment.