pixie/tests/benchmark_png.nim

53 lines
1.2 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":
2020-12-04 06:44:44 +00:00
keep decodePng(cast[seq[uint8]](data))
2020-11-21 02:21:27 +00:00
2020-11-23 04:01:56 +00:00
timeIt "pixie encode":
let decoded = decodePng(cast[seq[uint8]](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)
var write: WriteFunc = proc(closure: pointer, data: cstring, len: int32): Status {.cdecl.} =
StatusSuccess
discard decoded.writeToPng(write, nil)