Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
NextTick Implementation in GameLoop
(version: 1)
Comparing performance of:
Set vs For vs For [] vs While vs While If
Created:
9 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const ticks = 1000; const length = 10; let arr = []; const set = new Set();
Tests:
Set
for(let tickCount = 0; tickCount < ticks; tickCount++){ // NextTick for(const c of set){ c(); } set.clear(); // Game for(let i = 0; i < length; i++){ set.add(() => Math.random()); } }
For
for(let tickCount = 0; tickCount < ticks; tickCount++){ // NextTick arr.forEach((c) => c()); arr.length = 0; // Game for(let i = 0; i < length; i++){ arr.push(() => Math.random()); } }
For []
for(let tickCount = 0; tickCount < ticks; tickCount++){ // NextTick arr.forEach((c) => c()); arr = []; // Game for(let i = 0; i < length; i++){ arr.push(() => Math.random()); } }
While
for(let tickCount = 0; tickCount < ticks; tickCount++){ // NextTick while(true){ const c = arr.pop(); if(c === undefined) break; c(); } arr = []; // Game for(let i = 0; i < length; i++){ arr.push(() => Math.random()); } }
While If
for(let tickCount = 0; tickCount < ticks; tickCount++){ if(arr.length){ // NextTick while(true){ const c = arr.pop(); if(c === undefined) break; c(); } arr = []; } // Game for(let i = 0; i < length; i++){ arr.push(() => Math.random()); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Set
For
For []
While
While If
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
718.1 Ops/sec
For
3938.2 Ops/sec
For []
2391.8 Ops/sec
While
2666.3 Ops/sec
While If
2718.1 Ops/sec
Related benchmarks:
For Loop Approaches
For Loop Different Approaches
debounce test 2
let test
set.add test2
set.add test4
Array timing
Array timing 100
NextTick Implementation
Comments
Confirm delete:
Do you really want to delete benchmark?