Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Yield vs callback vs array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:150.0) Gecko/20100101 Firefox/150.0
Browser:
Firefox 150
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one month ago
Test name
Executions per second
iter
33.2 Ops/sec
callback
204.5 Ops/sec
cells
26.3 Ops/sec
Script Preparation code:
var size = 1000 var m = Array.from({length:size}).map((_,x)=>Array.from({length:size}).map((_,y)=>x*1000+y)) function* iter(ma) { const w = ma.length; const h=ma[0].length for (let x=0;x<w;x+=1){ for (let y=0;y<h;y+=1){ yield [x,y] } } } function callback(ma, cb) { const w = ma.length; const h=ma[0].length for (let x=0;x<w;x+=1){ for (let y=0;y<h;y+=1){ cb(x,y) } } } function cells(ma) { const res = [] const w = ma.length; const h=ma[0].length for (let x=0;x<w;x+=1){ for (let y=0;y<h;y+=1){ res.push([x,y]) } } return res }
Tests:
iter
const iterInst = iter(m) let sum = 0 for (const [x,y] of iterInst) { sum += m[x][y] } console.log(sum)
callback
let sum = 0; callback(m, (x,y)=>sum += m[x][y]) console.log(sum)
cells
const c = cells(m) let sum = 0 for (const [x,y] of c) { sum += m[x][y] } console.log(sum)