Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Optimization function
(version: 4)
Comparing performance of:
A vs B vs C
Created:
8 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var layr = 0; var map = { tileWidth: 32, tileHeight: 32, currentLayer: 0, layers: [{data: {width: 18, height: 18}}] } function snapToFloor(input, gap, start) { if (typeof start === "undefined") { start = 0; } if (gap == 0) { return input; } input -= start; input = gap * Math.floor(input / gap); return start + input; } function A(x, y, tileWidth, tileHeight, layr) { if (typeof layr === "undefined") { layr = map.currentLayer; } x = snapToFloor(x, tileWidth) / tileWidth; y = snapToFloor(y, tileHeight) / tileHeight; if (x >= 0 && x < map.layers[layr].width && y >= 0 && y < map.layers[layr].height) { return map.layers[layr].data[y][x]; } } function B(x, y, tileWidth, tileHeight, layr) { x = snapToFloor(x, tileWidth) / tileWidth; y = snapToFloor(y, tileHeight) / tileHeight; if (x >= 0 && x < map.layers[layr].width && y >= 0 && y < map.layers[layr].height) { return map.layers[layr].data[y][x]; } } function C(x, y, tileWidth, tileHeight, layr) { x = snapToFloor(x, tileWidth) / tileWidth; y = snapToFloor(y, tileHeight) / tileHeight; if (x < map.layers[layr].width && y < map.layers[layr].height) { return map.layers[layr].data[y][x]; } }
Tests:
A
for(var x = 0; x < 500; x++){ for(var y = 0; y < 500; y++){ A(x, y, map.tileWidth, map.tileHeight, layr); } }
B
for(var x = 0; x < 500; x++){ for(var y = 0; y < 500; y++){ B(x, y, map.tileWidth, map.tileHeight, layr); } }
C
for(var x = 0; x < 500; x++){ for(var y = 0; y < 500; y++){ C(x, y, map.tileWidth, map.tileHeight, layr); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
A
B
C
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
map vs _.map
native map vs _.map
Functional Vs Imperative
Memory Tests
Math.floor(N) vs (N | 0) vs parseInt(N)
Comments
Confirm delete:
Do you really want to delete benchmark?