pixie/tests/benchmark_png.nim

66 lines
1.4 KiB
Nim
Raw Normal View History

2021-06-25 21:54:32 +00:00
import benchy, cairo, nimPNG, pixie/fileformats/png, stb_image/read as stbi,
2021-02-14 18:27:32 +00:00
stb_image/write as stbr
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
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 decode + alpha":
discard newImage(decodePng(data))
2020-11-23 04:01:56 +00:00
2022-06-03 05:25:53 +00:00
timeIt "pixie encode + alpha":
discard encodePng(decodedImage)
block:
timeIt "nimPNG decode":
discard decodePNG32(data)
2020-11-21 02:21:27 +00:00
2020-11-23 04:01:56 +00:00
let decoded = decodePNG32(data)
2022-06-03 05:25:53 +00:00
timeIt "nimPNG encode":
discard encodePNG32(decoded.data, decoded.width, decoded.height)
2020-11-23 04:01:56 +00:00
2022-06-03 05:25:53 +00:00
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
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-06-03 05:25:53 +00:00
timeIt "stb_image encode":
discard writePNG(width, height, channels, decoded).len
2021-06-25 21:54:32 +00:00
2022-06-03 05:25:53 +00:00
block:
timeIt "cairo decode":
discard imageSurfaceCreateFromPng(filePath)
2021-06-25 21:54:32 +00:00
2022-06-03 05:25:53 +00:00
let decoded = imageSurfaceCreateFromPng(filePath)
timeIt "cairo encode":
var write: WriteFunc =
proc(closure: pointer, data: cstring, len: int32): Status {.cdecl.} =
StatusSuccess
discard decoded.writeToPng(write, nil)