pixie/tests/bench_png.nim

68 lines
1.6 KiB
Nim
Raw Normal View History

2022-07-10 18:12:45 +00:00
import benchy, pixie/fileformats/png
2020-11-21 02:21:27 +00:00
2021-06-25 21:54:32 +00:00
let
2021-10-03 22:49:21 +00:00
filePath = "tests/fileformats/png/lenna.png"
2021-06-25 21:54:32 +00:00
data = readFile(filePath)
2020-11-21 02:21:27 +00:00
2022-06-03 05:25:53 +00:00
block:
let
decodedPng = decodePng(data)
decodedImage = newImage(decodedPng)
2020-11-21 02:21:27 +00:00
2022-06-03 05:25:53 +00:00
timeIt "pixie decode":
discard decodePng(data)
2021-09-16 18:41:47 +00:00
timeIt "pixie decode + alpha":
discard decodePng(data).convertToImage()
2022-06-03 05:25:53 +00:00
timeIt "pixie encode":
discard encodePng(decodedPng)
2021-09-16 18:41:47 +00:00
2022-06-03 05:25:53 +00:00
timeIt "pixie encode + alpha":
discard encodePng(decodedImage)
2022-07-10 18:12:45 +00:00
# import nimPNG
# block:
# timeIt "nimPNG decode":
# discard decodePNG32(data)
2020-11-21 02:21:27 +00:00
2022-07-10 18:12:45 +00:00
# let decoded = decodePNG32(data)
# timeIt "nimPNG encode":
# discard encodePNG32(decoded.data, decoded.width, decoded.height)
2020-11-23 04:01:56 +00:00
2022-07-10 18:12:45 +00:00
# import stb_image/read as stbi, stb_image/write as stbr
# block:
# timeIt "stb_image decode":
# var width, height, channels: int
# discard loadFromMemory(
# cast[seq[byte]](data),
# width,
# height,
# channels,
# stbi.RGBA
# )
2020-11-23 04:01:56 +00:00
2022-07-10 18:12:45 +00:00
# var width, height, channels: int
# let decoded = loadFromMemory(
# cast[seq[byte]](data),
# width,
# height,
# channels,
# stbi.RGBA
# )
2021-06-25 21:54:32 +00:00
2022-07-10 18:12:45 +00:00
# timeIt "stb_image encode":
# discard writePNG(width, height, channels, decoded).len
2021-06-25 21:54:32 +00:00
2022-07-10 18:12:45 +00:00
# import cairo
# block:
# timeIt "cairo decode":
# discard imageSurfaceCreateFromPng(filePath.cstring)
2021-06-25 21:54:32 +00:00
# let decoded = imageSurfaceCreateFromPng(filePath.cstring)
# timeIt "cairo encode":
# var write: WriteFunc =
# proc(closure: pointer, data: cstring, len: int32): Status {.cdecl.} =
# StatusSuccess
# discard decoded.writeToPng(write, nil)