image loop benchmark
This commit is contained in:
parent
2afcbaa621
commit
5358ec6d19
1 changed files with 24 additions and 0 deletions
24
tests/benchmark_image_loop.nim
Normal file
24
tests/benchmark_image_loop.nim
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import benchy, pixie
|
||||||
|
|
||||||
|
let image = newImage(2560, 1440)
|
||||||
|
image.fill(rgba(50, 100, 150, 200))
|
||||||
|
|
||||||
|
timeIt "x then y":
|
||||||
|
var sum: uint64
|
||||||
|
for x in 0 ..< image.width:
|
||||||
|
for y in 0 ..< image.height:
|
||||||
|
let pixel = image.getRgbaUnsafe(x, y)
|
||||||
|
sum += pixel.r + pixel.g + pixel.b + pixel.a
|
||||||
|
if sum == 0:
|
||||||
|
echo "0"
|
||||||
|
keep sum
|
||||||
|
|
||||||
|
timeIt "y then x":
|
||||||
|
var sum: uint64
|
||||||
|
for y in 0 ..< image.height:
|
||||||
|
for x in 0 ..< image.width:
|
||||||
|
let pixel = image.getRgbaUnsafe(x, y)
|
||||||
|
sum += pixel.r + pixel.g + pixel.b + pixel.a
|
||||||
|
if sum == 0:
|
||||||
|
echo "0"
|
||||||
|
keep sum
|
Loading…
Reference in a new issue