pixie/tests/benchmark_png.nim

61 lines
1.3 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
filePath = "tests/images/png/lenna.png"
data = readFile(filePath)
2020-11-21 02:21:27 +00:00
2020-11-23 04:01:56 +00:00
timeIt "pixie decode":
2021-09-16 18:41:47 +00:00
keep decodePngRaw(data)
2020-11-21 02:21:27 +00:00
2020-11-23 04:01:56 +00:00
timeIt "pixie encode":
2021-09-16 18:41:47 +00:00
let decoded = decodePngRaw(data)
keep encodePng(decoded).len
timeIt "pixie decode + alpha":
keep decodePng(data)
timeIt "pixie encode + alpha":
let decoded = decodePng(data)
2020-12-04 06:44:44 +00:00
keep encodePng(decoded).len
2020-11-23 04:01:56 +00:00
timeIt "nimPNG decode":
2020-12-04 06:44:44 +00:00
keep decodePNG32(data)
2020-11-21 02:21:27 +00:00
2020-11-23 04:01:56 +00:00
timeIt "nimPNG encode":
let decoded = decodePNG32(data)
2020-12-04 06:44:44 +00:00
keep encodePNG32(decoded.data, decoded.width, decoded.height).pixels.len
2020-11-23 04:01:56 +00:00
timeIt "stb_image decode":
2020-12-04 06:44:44 +00:00
var width, height, channels: int
keep loadFromMemory(
cast[seq[byte]](data),
width,
height,
channels,
stbi.RGBA
)
2020-11-23 04:01:56 +00:00
timeIt "stb_image encode":
var width, height, channels: int
let decoded = loadFromMemory(
cast[seq[byte]](data),
width,
height,
channels,
stbi.RGBA
)
2020-12-04 06:44:44 +00:00
keep writePNG(width, height, channels, decoded).len
2021-06-25 21:54:32 +00:00
timeIt "cairo decode":
keep imageSurfaceCreateFromPng(filePath)
timeIt "cairo encode":
let decoded = imageSurfaceCreateFromPng(filePath)
2021-06-27 04:16:35 +00:00
var write: WriteFunc =
proc(closure: pointer, data: cstring, len: int32): Status {.cdecl.} =
StatusSuccess
2021-06-25 21:54:32 +00:00
discard decoded.writeToPng(write, nil)