Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Yield vs callback vs array
(version: 1)
Comparing performance of:
iter vs callback vs cells
Created:
one month ago
by:
Guest
Jump to the latest result
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)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
iter
callback
cells
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:150.0) Gecko/20100101 Firefox/150.0
Browser/OS:
Firefox 150 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
iter
33.2 Ops/sec
callback
204.5 Ops/sec
cells
26.3 Ops/sec
Related benchmarks:
Map vs Object 123
Map vs Object 1234
Map vs Object 12345
Map vs Object 123456
Large nested Arrays: Immutable.js vs spread operator
Comparison of three map functions
Find last element of an array
Find last element of an array no empty array
flat typed array vs 2d typed array
Comments
Confirm delete:
Do you really want to delete benchmark?