-- Throughput (bash tools/bench.sh): codec MB/s under both runtimes. MB/s are of decompressed output, best of n runs. -- Fixtures: tools/fixtures/deflate.py (a 6 MB corpus), tools/fixtures/png.py (1024 x 768 images), tools/fixtures/mp3.py, -- tools/fixtures/opus.py (3 s stereo files; MB/s of f32 output, 48 kHz stereo f32 is 0.384 MB/s of real time), -- tools/fixtures/flac.py; wav encodes / decodes a generated tone; zstd / brotli / bzip2 / lzma / lz4 (*_bench corpora), fonts -- (glyphs per second), json / xml / yaml, jpeg / gif / tiff / qoi / tga / pnm / hdr and ImageOps. local Deflate = require("@formats/codecs/compress/Deflate") local Crc32 = require("@formats/core/Crc32") local Bytes = require("@formats/core/Bytes") local Png = require("@formats/image/png") local B = require("@tests/gen/deflate_bench") local PB = require("@tests/gen/png_bench") local Mp3 = require("@formats/audio/mp3") local MC = require("@tests/gen/mp3_cases") local Opus = require("@formats/audio/opus") local OpusCelt = require("@tests/gen/opus_celt_st_128") local OpusSilk = require("@tests/gen/opus_silk_wb_st") local OpusHybrid = require("@tests/gen/opus_hybrid_st") local Flac = require("@formats/audio/flac") local FC = require("@tests/gen/flac_cases") local Wav = require("@formats/audio/wav") local Types = require("@formats/Types") local runtime = if (_G :: any).jit ~= nil then "luajit" else "luau" -- jitTune(on): LuaJIT's trace limits as host/init.luau sets them for the api (on) or LuaJIT's defaults (off); the -- codec sections that care print both local function jitTune(on: boolean) local jit = (_G :: any).jit if jit and type(jit.opt) == "table" then if on then jit.opt.start("maxtrace=8000", "maxmcode=65536") else jit.opt.start("maxtrace=1000", "maxmcode=8192") end end end local function bench(label: string, n: number, bytes: number, f: () -> ()) f() local dt = math.huge -- best of n: the machine is shared, the mean is noisy for _ = 1, n do local t0 = os.clock() f() dt = math.min(dt, os.clock() - t0) end print(string.format("%-8s %-30s %8.2f ms %7.1f MB/s", runtime, label, dt * 1000, bytes / dt / 1e6)) return dt end local z = buffer.fromstring(B.zlib) local g = buffer.fromstring(B.gzip) local out = assert(Deflate.zlib(z)) assert(buffer.len(out) == B.size and Crc32.of(out) == B.crc, "bench corpus mismatch") bench("inflate (growing output)", 5, B.size, function() Deflate.inflate(z, 2, buffer.len(z) - 6) end) bench("inflate (exact size)", 5, B.size, function() Deflate.inflate(z, 2, buffer.len(z) - 6, B.size) end) bench("zlib (+ adler32)", 5, B.size, function() Deflate.zlib(z) end) bench("gunzip (+ crc32)", 5, B.size, function() Deflate.gunzip(g) end) bench("crc32", 10, B.size, function() Crc32.of(out) end) local part = buffer.create(1500000) buffer.copy(part, 0, out, 0, 1500000) bench("compress -6 (1.5 MB in)", 2, 1500000, function() Deflate.compress(part, { level = 6 }) end) for _, c in PB do local b = buffer.fromstring(c.data) bench("png decode " .. c.name, 3, c.width * c.height * 4, function() Png.decode(Bytes.reader(b)) end) end do local img = assert(Png.decode(Bytes.reader(buffer.fromstring(PB[1].data)))) bench("png encode rgba8", 2, img.width * img.height * 4, function() Png.encode(img) end) end for _, name in { "l3_cbr128_js", "l3_vbr_v2_48k", "l2_192_st" } do for _, c in MC do if c.name == name then local b = buffer.fromstring(c.data) local dec = assert(Mp3.open(Bytes.reader(b))) local secs = dec.duration local dt = bench("mp3 decode " .. name, 5, dec.frames * dec.channels * 4, function() local d = assert(Mp3.open(Bytes.reader(b))) d:readAll() end) print(string.format("%-8s %-30s %8.0fx real time", runtime, "", secs / dt)) end end end for _, c in { { "celt 128k", OpusCelt }, { "silk wb", OpusSilk }, { "hybrid", OpusHybrid } } do local b = buffer.fromstring(c[2].data) bench("opus decode " .. c[1] .. " (3 s st)", 3, #c[2].ref, function() Opus.decode(Bytes.reader(b)) end) end -- vorbis (ws-audio): 10 s of 44.1 kHz stereo music at oggenc -q 5 (tools/fixtures/vorbis.py) do local Vorbis = require("@formats/audio/vorbis") local VB = require("@tests/gen/vorbis_bench") local b = buffer.fromstring(VB.data) local dt = bench("vorbis decode q5 (10 s st)", 3, VB.frames * VB.channels * 4, function() Vorbis.decode(Bytes.reader(b)) end) print(string.format("%-8s %-30s %8.0fx real time", runtime, "", VB.frames / VB.rate / dt)) end for _, name in { "s16_long", "s24_96k" } do for _, c in FC do if c.name == name then local b = buffer.fromstring(c.data) local dec = assert(Flac.open(Bytes.reader(b))) local secs = dec.duration local dt = bench("flac decode " .. name, 5, dec.frames * dec.channels * 4, function() Flac.decode(Bytes.reader(b)) end) print(string.format("%-8s %-30s %8.0fx real time", runtime, "", secs / dt)) end end end do local a = Types.Audio.new(44100, 2, 44100 * 10) for i = 0, 44100 * 20 - 1 do buffer.writef32(a.samples, i * 4, math.sin(i * 0.01) * 0.5) end bench("wav encode s16 (10 s stereo)", 5, buffer.len(a.samples), function() Wav.encode(a) end) local file = assert(Wav.encode(a)) bench("wav decode s16 (10 s stereo)", 5, buffer.len(a.samples), function() Wav.decode(Bytes.reader(file)) end) end -- flac encode (ws-audio): 10 s of 44.1 kHz stereo 16-bit (a synthetic two-tone signal with noise) do local Fl = require("@formats/audio/flac") local n = 441000 local a = Types.Audio.new(44100, 2, n) local seed = 1 for i = 0, n - 1 do seed = (seed * 1103515245 + 12345) % 2147483648 local noise = (seed / 2147483648 - 0.5) * 0.01 buffer.writef32(a.samples, i * 8, math.floor((math.sin(i * 0.031) * 0.4 + math.sin(i * 0.21) * 0.1 + noise) * 32768) / 32768) buffer.writef32(a.samples, i * 8 + 4, math.floor((math.sin(i * 0.017) * 0.3 + noise) * 32768) / 32768) end for _, level in { 0, 5, 8 } do local dt = bench("flac encode -" .. level .. " (10 s st 16)", 2, n * 4, function() Fl.encode(a, { level = level }) end) print(string.format("%-8s %-30s %8.0fx real time", runtime, "", 10 / dt)) end end -- mp3 / mp2 encode (ws-audio): 10 s of 44.1 kHz stereo tones do local M3 = require("@formats/audio/mp3") local n = 441000 local a = Types.Audio.new(44100, 2, n) for i = 0, n - 1 do buffer.writef32(a.samples, i * 8, math.sin(i * 0.031) * 0.4 + math.sin(i * 0.21) * 0.1) buffer.writef32(a.samples, i * 8 + 4, math.sin(i * 0.017) * 0.3) end for _, cfg in { { layer = 3, bitrate = 128 }, { layer = 2, bitrate = 192 } } do local dt = bench(string.format("mp%d encode %d kbps (10 s st)", cfg.layer, cfg.bitrate), 2, n * 8, function() M3.encode(a, cfg) end) print(string.format("%-8s %-30s %8.1fx real time", runtime, "", 10 / dt)) end end -- vorbis encode (ws-audio): 10 s of 44.1 kHz stereo tones at quality 3 do local Vb = require("@formats/audio/vorbis") local n = 441000 local a = Types.Audio.new(44100, 2, n) for i = 0, n - 1 do buffer.writef32(a.samples, i * 8, math.sin(i * 0.031) * 0.4 + math.sin(i * 0.21) * 0.1) buffer.writef32(a.samples, i * 8 + 4, math.sin(i * 0.017) * 0.3) end local dt = bench("vorbis encode q3 (10 s st)", 2, n * 8, function() Vb.encode(a, { quality = 3 }) end) print(string.format("%-8s %-30s %8.1fx real time", runtime, "", 10 / dt)) end do local Json = require("@formats/codecs/text/Json") local JB = require("@tests/gen/json_bench") local v = assert(Json.decode(JB.text)) assert(Json.encode(v) == JB.compact, "json bench mismatch") bench("json decode (indented)", 5, #JB.text, function() Json.decode(JB.text) end) bench("json decode (compact)", 5, #JB.compact, function() Json.decode(JB.compact) end) bench("json encode (compact, sorted)", 5, #JB.compact, function() Json.encode(v) end) end do local Xml = require("@formats/codecs/text/Xml") local XB = require("@tests/gen/xml_bench") local doc = assert(Xml.decode(XB.text)) bench("xml decode (DOM)", 5, #XB.text, function() Xml.decode(XB.text) end) bench("xml events", 5, #XB.text, function() for _ in Xml.events(XB.text) do end end) bench("xml encode", 5, #XB.text, function() Xml.encode(doc) end) end -- ws-arch codecs: zstd, brotli, bzip2, xz / lzma do local Zstd = require("@formats/codecs/compress/Zstd") local ZB = require("@tests/gen/zstd_bench") local z3, z19 = buffer.fromstring(ZB.data3), buffer.fromstring(ZB.data19) local zo = assert(Zstd.decompress(z3)) assert(buffer.len(zo) == ZB.size and Crc32.of(zo) == ZB.crc, "zstd bench corpus mismatch") bench("zstd -3 (+ xxh64)", 3, ZB.size, function() Zstd.decompress(z3) end) bench("zstd -3 (no checksum)", 3, ZB.size, function() Zstd.decompress(z3, nil, nil, { verify = false }) end) bench("zstd -19 (no checksum)", 3, ZB.size, function() Zstd.decompress(z19, nil, nil, { verify = false }) end) end do local Lz4 = require("@formats/codecs/compress/Lz4") local LB = require("@tests/gen/lz4_bench") local lz = buffer.fromstring(LB.data) local raw = assert(Lz4.decompress(lz, nil, nil, LB.size)) assert(Crc32.of(raw) == LB.crc, "lz4 bench corpus mismatch") bench("lz4 block decompress (hc9)", 5, LB.size, function() Lz4.decompress(lz, nil, nil, LB.size) end) bench("lz4 block compress", 3, LB.size, function() Lz4.compress(raw) end) end -- ws-roblox: a model of 20000 parts (built here) through model/rbxm and model/rbxmx, and a .mesh decode do local Rbx = require("@formats/codecs/model/Rbx") local Rbxm = require("@formats/model/rbxm") local Rbxmx = require("@formats/model/rbxmx") local RobloxMesh = require("@formats/model/robloxmesh") local tree = Rbx.tree() local folder = Rbx.add(tree, Rbx.instance("Folder", "Parts")) for i = 1, 20000 do local p = Rbx.add(folder, Rbx.instance("Part", "P" .. i)) Rbx.set(p, "CFrame", "CFrame", { i, i % 7, -i, 1, 0, 0, 0, 1, 0, 0, 0, 1 }) Rbx.set(p, "size", "Vector3", { 4, 1, 2 + i % 3 }) Rbx.set(p, "Color3uint8", "Color3uint8", { i % 256, 128, 255 - i % 256 }) Rbx.set(p, "Anchored", "Bool", i % 2 == 0) Rbx.set(p, "Transparency", "Float32", (i % 4) / 4) Rbx.set(p, "Material", "Enum", 256) end local bin = Rbxm.encode(tree) :: buffer local xml = Rbxmx.encode(tree) :: buffer bench("rbxm decode (20k parts)", 3, buffer.len(bin), function() Rbxm.decode(Bytes.reader(bin)) end) bench("rbxm encode (20k parts)", 3, buffer.len(bin), function() Rbxm.encode(tree) end) bench("rbxmx decode (20k parts)", 3, buffer.len(xml), function() Rbxmx.decode(Bytes.reader(xml)) end) local M = require("@tests/gen/robloxmesh") local mesh = buffer.fromstring(M.cases[#M.cases - 1].data) bench("robloxmesh decode (v7, skinned)", 20, buffer.len(mesh), function() RobloxMesh.decode(Bytes.reader(mesh)) end) end do local Brotli = require("@formats/codecs/compress/Brotli") local BB = require("@tests/gen/brotli_bench") local bz = buffer.fromstring(BB.data) local bout = assert(Brotli.decompress(bz)) assert(buffer.len(bout) == BB.size and Crc32.of(bout) == BB.crc, "brotli bench corpus mismatch") bench("brotli decompress (q9 w22)", 5, BB.size, function() Brotli.decompress(bz) end) end do local Bzip2 = require("@formats/codecs/compress/Bzip2") local BZ = require("@tests/gen/bzip2_bench") local bz = buffer.fromstring(BZ.data) bench("bzip2 decompress -9", 3, BZ.size, function() Bzip2.decompress(bz) end) end do local Lzma = require("@formats/codecs/compress/Lzma") local LB = require("@tests/gen/lzma_bench") local lx, la = buffer.fromstring(LB.xz), buffer.fromstring(LB.alone) local lo = assert(Lzma.xz(lx)) assert(buffer.len(lo) == LB.size and Crc32.of(lo) == LB.crc, "lzma bench corpus mismatch") bench("xz -6 (lzma2 + crc64)", 3, LB.size, function() Lzma.xz(lx) end) bench("lzma alone -6", 3, LB.size, function() Lzma.alone(la) end) end -- fonts: outlines and rasterization (MB/s here = thousands of glyphs per second) do local Ttf = require("@formats/font/ttf") local FX = require("@tests/gen/fonts") for _, c in FX.fonts do if c.name == "Roboto-Medium" or c.name == "SourceSans3-Regular" then local f = assert(Ttf.decode(Bytes.reader(buffer.fromstring(c.data)))) local gl = {} for cp = 33, 126 do table.insert(gl, f:glyphIndex(cp)) end bench(c.name .. " outlines (kglyph/s)", 3, #gl * 1000, function() for _, g in gl do f:outline(g) end end) bench(c.name .. " rasterize 32 px (kglyph/s)", 3, #gl * 1000, function() for _, g in gl do f:rasterize(g, 32) end end) end end end do local Yaml = require("@formats/data/yaml") local YB = require("@tests/gen/yaml_bench") local yb = buffer.fromstring(YB.text) local v = assert(Yaml.decode(Bytes.reader(yb))) bench("yaml decode (block)", 3, #YB.text, function() Yaml.decode(Bytes.reader(yb)) end) bench("yaml encode", 3, #YB.text, function() Yaml.encode(v) end) end -- ------------------------------------------------------------------------------------------------ jpeg (ws-imgA) do local Jpeg = require("@formats/image/jpeg") local Types = require("@formats/Types") local JB = require("@tests/gen/jpeg_bench") for _, c in JB.files do local b = buffer.fromstring(c.data) local img = Jpeg.decode(Bytes.reader(b)) assert(img and Crc32.of(img.pixels) == c.crc, "jpeg bench: " .. c.name .. " does not match djpeg") bench("jpeg decode " .. c.name, 3, c.width * c.height * 4, function() Jpeg.decode(Bytes.reader(b)) end) end local b0 = buffer.fromstring(JB.files[1].data) bench("jpeg decode 1/8 (DC only)", 3, JB.width * JB.height * 4, function() Jpeg.decode(Bytes.reader(b0), { scale = 8 }) end) local src = Types.Image.new(JB.width, JB.height, "rgb8") buffer.writestring(src.pixels, 0, JB.rgb) for _, o in { { label = "baseline 4:2:0 q85", quality = 85 }, { label = "progressive 4:2:0 q85", quality = 85, progressive = true }, { label = "baseline 4:4:4 q85 optimized", quality = 85, subsampling = "444", optimize = true } } do bench("jpeg encode " .. o.label, 2, JB.width * JB.height * 3, function() Jpeg.encode(src, o :: any) end) end end -- ---------------------------------------------------------------------------------------- ws-imgA: gif + quantize do local Gif = require("@formats/image/gif") local Quantize = require("@formats/codecs/image/Quantize") local Types = require("@formats/Types") local GB = require("@tests/gen/gif_bench") local still = buffer.fromstring(GB.still) local anim = buffer.fromstring(GB.anim) local simg = assert(Gif.decode(Bytes.reader(still))) local aimg = assert(Gif.decode(Bytes.reader(anim))) local sw, sh = simg.width, simg.height bench("gif decode 512x384", 5, sw * sh * 4, function() Gif.decode(Bytes.reader(still)) end) bench("gif decode 40 x 128x128 anim", 3, #(aimg.frames :: any) * 128 * 128 * 4, function() Gif.decode(Bytes.reader(anim)) end) bench("gif encode 512x384 (exact pal)", 3, sw * sh * 4, function() Gif.encode(simg) end) local photo = Types.Image.new(sw, sh) for i = 0, sw * sh - 1 do local x, y = i % sw, i // sw buffer.writeu32(photo.pixels, i * 4, (x % 256) + (y % 256) * 256 + ((x * y) % 256) * 65536 + 0xFF000000) end bench("quantize mediancut 256", 3, sw * sh * 4, function() Quantize.palette(photo.pixels, sw, sh, 256) end) bench("quantize octree 256", 3, sw * sh * 4, function() Quantize.palette(photo.pixels, sw, sh, 256, { method = "octree" }) end) local pal = Quantize.palette(photo.pixels, sw, sh, 256) bench("quantize map", 3, sw * sh * 4, function() Quantize.map(photo.pixels, sw, sh, pal) end) bench("quantize map + dither", 3, sw * sh * 4, function() Quantize.map(photo.pixels, sw, sh, pal, { dither = true }) end) bench("gif encode 512x384 (quantize)", 2, sw * sh * 4, function() Gif.encode(photo) end) end -- ------------------------------------------------------------------------------------------------ ops/ImageOps do local Ops = require("@formats/ops/ImageOps") local img = assert(Png.decode(Bytes.reader(buffer.fromstring(PB[1].data)))) local n = img.width * img.height * 4 bench("imageops resize 1/2 bilinear", 2, n, function() Ops.resize(img, img.width // 2, img.height // 2, "bilinear") end) bench("imageops resize 1/2 lanczos", 2, n, function() Ops.resize(img, img.width // 2, img.height // 2, "lanczos") end) bench("imageops resize x1.5 bilinear", 1, n, function() Ops.resize(img, img.width * 3 // 2, img.height * 3 // 2, "bilinear") end) bench("imageops rotate 30 (expand)", 1, n, function() Ops.rotate(img, 30) end) bench("imageops rotate90", 3, n, function() Ops.rotate90(img, 1) end) bench("imageops convert rgba8 -> gray8", 3, n, function() Ops.convert(img, "gray8") end) local other = assert(Ops.flip(img, "h")) bench("imageops composite over", 3, n, function() Ops.composite(img, other) end) end -- ------------------------------------------------------------------------------------------------ image/tiff (ws-imgA) do local Tiff = require("@formats/image/tiff") local Types = require("@formats/Types") local src = Types.Image.new(1024, 768) for i = 0, 1024 * 768 - 1 do local x, y = i % 1024, i // 1024 buffer.writeu32(src.pixels, i * 4, 0xFF000000 + (x % 256) + ((y % 256) * 256) + (((x + y) // 4 % 256) * 65536)) end for _, comp in { "none", "lzw", "deflate" } do local enc = Tiff.encode(src, { compression = comp :: any }) :: buffer bench("tiff decode rgba8 " .. comp, 3, 1024 * 768 * 4, function() Tiff.decode(Bytes.reader(enc)) end) bench("tiff encode rgba8 " .. comp, 2, 1024 * 768 * 4, function() Tiff.encode(src, { compression = comp :: any }) end) end local enc16 = Tiff.encode(Types.Image.new(1024, 768, "rgba16"), { compression = "lzw" }) :: buffer bench("tiff decode rgba16 lzw -> rgba8", 3, 1024 * 768 * 8, function() Tiff.decode(Bytes.reader(enc16)) end) end -- ------------------------------------------------------------------------------------------------ imgA-simple: qoi / tga / pnm / hdr -- fixtures: tools/fixtures/qoi.py (tests/gen/qoi_bench.luau: run python3 -I tools/fixtures.py qoi first) do local Qoi = require("@formats/image/qoi") local Tga = require("@formats/image/tga") local Pnm = require("@formats/image/pnm") local Hdr = require("@formats/image/hdr") local Types = require("@formats/Types") local QB = require("@tests/gen/qoi_bench") local qd = buffer.fromstring(QB.data) local n = QB.width * QB.height * 4 bench("qoi decode 1024x768", 5, n, function() Qoi.decode(Bytes.reader(qd)) end) local img = Types.Image.new(QB.width, QB.height) img.pixels = buffer.fromstring(QB.pixels) bench("qoi encode 1024x768", 5, n, function() Qoi.encode(img) end) local tr = Tga.encode(img, { rle = true }) :: buffer bench("tga decode rle 1024x768", 3, n, function() Tga.decode(Bytes.reader(tr)) end) bench("tga encode rle 1024x768", 3, n, function() Tga.encode(img, { rle = true }) end) local pp = Pnm.encode(img, { format = "ppm" }) :: buffer bench("ppm decode 1024x768", 3, n, function() Pnm.decode(Bytes.reader(pp)) end) local f = Hdr.decode(Bytes.reader(Hdr.encode(img) :: buffer), { native = true }) :: Types.Image local hb = Hdr.encode(f) :: buffer bench("hdr decode rle 1024x768 (rgbaf32)", 3, n, function() Hdr.decode(Bytes.reader(hb), { native = true }) end) bench("hdr encode rle 1024x768", 3, n, function() Hdr.encode(f) end) end do -- 3D (ws-3d): a 400 x 400 grid mesh (160k vertices, 318k triangles) through our own writers, then the readers; a -- 128^3 noise voxel grid through VOX and greedy meshing local Types = require("@formats/Types") local MeshOps = require("@formats/ops/MeshOps") local Gltf = require("@formats/model/gltf") local Obj = require("@formats/model/obj") local Stl = require("@formats/model/stl") local Ply = require("@formats/model/ply") local Vox = require("@formats/model/vox") local N = 400 local pos = Types.Scene.accessor(nil, "f32", 3, N * N) local uv = Types.Scene.accessor(nil, "f32", 2, N * N) for y = 0, N - 1 do for x = 0, N - 1 do local i = y * N + x buffer.writef32(pos.data, i * 12, x / N) buffer.writef32(pos.data, i * 12 + 4, math.sin(x * 0.1) * math.cos(y * 0.1) * 0.05) buffer.writef32(pos.data, i * 12 + 8, y / N) buffer.writef32(uv.data, i * 8, x / N) buffer.writef32(uv.data, i * 8 + 4, y / N) end end local ind = Types.Scene.accessor(nil, "u32", 1, (N - 1) * (N - 1) * 6) local k = 0 for y = 0, N - 2 do for x = 0, N - 2 do local a = y * N + x for _, v in { a, a + N, a + 1, a + 1, a + N, a + N + 1 } do buffer.writeu32(ind.data, k * 4, v) k += 1 end end end local prim = { attributes = { POSITION = pos, TEXCOORD_0 = uv }, indices = ind, mode = "triangles" } :: any MeshOps.computeNormals(prim) local scene = Types.Scene.fromPrimitive(prim, "grid") bench("meshops computeNormals 318k tris", 3, buffer.len(pos.data), function() MeshOps.computeNormals(prim) end) local glb = assert(Gltf.encode(scene, { binary = true })) bench("gltf glb decode (" .. buffer.len(glb) // 1000 .. " KB)", 5, buffer.len(glb), function() Gltf.decode(Bytes.reader(glb)) end) bench("gltf glb encode", 3, buffer.len(glb), function() Gltf.encode(scene, { binary = true }) end) local obj = assert(Obj.encode(scene)) bench("obj decode (" .. buffer.len(obj) // 1000 .. " KB)", 2, buffer.len(obj), function() Obj.decode(Bytes.reader(obj)) end) bench("obj encode", 2, buffer.len(obj), function() Obj.encode(scene) end) local stl = assert(Stl.encode(scene)) bench("stl binary decode (" .. buffer.len(stl) // 1000 .. " KB)", 5, buffer.len(stl), function() Stl.decode(Bytes.reader(stl)) end) local ply = assert(Ply.encode(scene)) bench("ply binary decode (" .. buffer.len(ply) // 1000 .. " KB)", 5, buffer.len(ply), function() Ply.decode(Bytes.reader(ply)) end) local V = 128 local grid = Types.Voxels.new(V, V, V) for z = 0, V - 1 do for y = 0, V - 1 do for x = 0, V - 1 do local h = (math.sin(x * 0.11) + math.cos(y * 0.07) + 2) * V / 8 + z * 0 if z < h then Types.Voxels.set(grid, x, y, z, 1 + (x // 8 + y // 8) % 6) end end end end local vox = assert(Vox.encode(grid)) bench("vox decode (" .. buffer.len(vox) // 1000 .. " KB)", 5, buffer.len(vox), function() Vox.decode(Bytes.reader(vox)) end) bench("greedy mesh 128^3 (MB of cells)", 3, V * V * V, function() MeshOps.voxelsToPrimitive(grid) end) end do -- layered + vector (ws-vec): PSD decode / encode of 8 RGBA layers 1024 x 768, flatten (codecs/image/Blend), SVG -- rasterize at 512 x 512 (codecs/image/Raster). No fixtures: the inputs are built here. local Types = require("@formats/Types") local Psd = require("@formats/layered/psd") local LayerOps = require("@formats/ops/LayerOps") local Svg = require("@formats/vector/svg") local W, H = 1024, 768 local doc = Types.Layered.new(W, H) local modes = { "normal", "multiply", "screen", "overlay", "normal", "softLight", "difference", "normal" } for k = 1, 8 do local img = Types.Image.new(W, H) local px = img.pixels for i = 0, W * H - 1 do local x, y = i % W, i // W buffer.writeu32(px, i * 4, ((x * k) % 256) + ((y * 3) % 256) * 256 + (((x + y) // 4) % 256) * 65536 + (if (x // 64 + y // 64 + k) % 3 == 0 then 0 else 200) * 16777216) end local l = Types.Layered.layer("L" .. k, img) l.blend = modes[k] doc.layers[k] = l end local psd = assert(Psd.encode(doc)) bench("psd decode 8 layers 1024x768", 2, W * H * 4 * 9, function() Psd.decode(Bytes.reader(psd)) end) bench("psd encode 8 layers (RLE)", 1, W * H * 4 * 9, function() Psd.encode(doc) end) bench("flatten 8 layers (blend modes)", 2, W * H * 4 * 8, function() LayerOps.flatten(doc) end) local shapes = {} for k = 0, 39 do table.insert(shapes, string.format("", (k * 37) % 100, (k * 53) % 100, 5 + k % 12)) table.insert(shapes, string.format("", k % 50, k * 2, k * 9)) end local text = "" .. table.concat(shapes) .. "" local v = assert(Svg.decode(Bytes.reader(buffer.fromstring(text)))) bench("svg parse (80 elements)", 5, #text, function() Svg.decode(Bytes.reader(buffer.fromstring(text))) end) bench("svg rasterize 512x512 (80 shapes)", 2, 512 * 512 * 4, function() Svg.rasterize(v, 512, 512) end) end do local Webp = require("@formats/image/webp") local WB = require("@tests/gen/webp_bench") local n = WB.width * WB.height * 4 local lossy, lossless = buffer.fromstring(WB.lossy), buffer.fromstring(WB.lossless) bench("webp lossy decode 512x512", 3, n, function() Webp.decode(Bytes.reader(lossy)) end) bench("webp lossless decode 512x512", 3, n, function() Webp.decode(Bytes.reader(lossless)) end) local img = assert(Webp.decode(Bytes.reader(lossless))) bench("webp lossless encode (effort 5)", 1, n, function() Webp.encode(img) end) bench("webp lossless encode (effort 1)", 1, n, function() Webp.encode(img, { effort = 1 }) end) end do local Xml = require("@formats/codecs/text/Xml") local XB = require("@tests/gen/xml_bench") local doc = assert(Xml.decode(XB.text)) bench("xml decode (DOM)", 5, #XB.text, function() Xml.decode(XB.text) end) bench("xml events", 5, #XB.text, function() for _ in Xml.events(XB.text) do end end) bench("xml encode", 5, #XB.text, function() Xml.encode(doc) end) end -- ws-m4a: AAC-LC / ALAC decode and ALAC encode (MB/s of 16-bit PCM equivalent: frames * channels * 2), MDCT do local M4a = require("@formats/audio/m4a") local Alac = require("@formats/codecs/audio/Alac") local Mdct = require("@formats/codecs/audio/Mdct") local MA = require("@tests/gen/m4a_aac") local ML = require("@tests/gen/m4a_alac") local aac = buffer.fromstring(MA[1].data) local a = assert(M4a.decode(Bytes.reader(aac))) bench("aac-lc decode (m4a, stereo)", 3, a.frames * a.channels * 2, function() M4a.decode(Bytes.reader(aac)) end) local alac = buffer.fromstring(ML[1].data) local l = assert(M4a.decode(Bytes.reader(alac))) bench("alac decode (m4a, stereo 16)", 3, l.frames * l.channels * 2, function() M4a.decode(Bytes.reader(alac)) end) local enc = assert(Alac.encoder({ sampleRate = 44100, channels = 2, bitDepth = 16 })) local ints = table.create(a.frames * 2, 0) for i = 1, a.frames * 2 do ints[i] = math.floor(buffer.readf32(a.samples, (i - 1) * 4) * 32767) end bench("alac encode (stereo 16)", 2, a.frames * 2 * 2, function() local f = 0 while f < a.frames do local n = math.min(4096, a.frames - f) enc:encode(ints, f * 2 + 1, n) f += n end end) local plan = assert(Mdct.new(2048)) local x, X = table.create(2048, 0.5), table.create(1024, 0) bench("mdct 2048 x 1000 (forward)", 3, 1000 * 2048 * 4, function() for _ = 1, 1000 do Mdct.forward(plan, x, 1, X, 1) end end) end do local Opus = require("@formats/audio/opus") local Cases = require("@tests/audio/_opus_cases") local c = Cases.list[2] local a = Cases.signal(c) local dt = bench("opus celt encode 128k (1.5 s st)", 2, a.frames * a.channels * 2, function() Opus.encode(a, { bitrate = 128000 }) end) local _ = dt end -- MIDI through the SoundFont synth (tools/fixtures/sf2.py's test song; tools/fixtures/midi.py's "song" through the -- built-in waveform set): seconds of stereo 44.1 kHz audio rendered per second of CPU do local Midi = require("@formats/music/midi") local Sf2 = require("@formats/music/sf2") local SF = require("@tests/gen/sf2_cases") local MC = require("@tests/gen/midi_cases") local sf = assert(Sf2.decode(Bytes.reader(buffer.fromstring(SF.sf2)))) local function realtime(label: string, data: string, font: any) local song = assert(Midi.decode(Bytes.reader(buffer.fromstring(data)))) local best = math.huge local frames = 0 for _ = 1, 3 do local dec = assert(Midi.render(song, { soundfont = font, tail = 0 })) local out = buffer.create(4096 * 8) local t0 = os.clock() frames = 0 while true do local _, n = dec:read(4096, out) if n == 0 then break end frames += n end best = math.min(best, os.clock() - t0) end print(string.format("%-8s %-30s %8.2f ms %7.1f x realtime", runtime, label, best * 1000, frames / 44100 / best)) end realtime("midi render sf2 (test song)", SF.song, sf) for _, c in MC do if c.name == "song" then realtime("midi render fallback", c.data, nil) end end end -- the synth's per-voice cost: 32 sustained, filtered, looped voices (sf2 saw preset with a mod env) for 2 s do local SoundFont = require("@formats/codecs/audio/SoundFont") local Sf2 = require("@formats/music/sf2") local SF = require("@tests/gen/sf2_cases") local sf = assert(Sf2.decode(Bytes.reader(buffer.fromstring(SF.sf2)))) local frames = 88200 local out = buffer.create(frames * 8) local best = math.huge for _ = 1, 3 do local s = SoundFont.synth(sf, 44100) SoundFont.Synth.midi(s, 0xC0, 1, 0) for k = 0, 31 do SoundFont.Synth.midi(s, 0x90, 40 + k, 100) end buffer.fill(out, 0, 0) local t0 = os.clock() for f = 0, frames - 1, 1024 do SoundFont.Synth.render(s, out, f, 1024) end best = math.min(best, os.clock() - t0) end print(string.format("%-8s %-30s %8.2f ms %7.1f M voice-samples/s", runtime, "synth 32 voices x 2 s", best * 1000, 32 * frames / best / 1e6)) end -- the tracker engine: 32 channels of looped samples (one note each, linear interpolation, volume ramps), and an -- IT-style module with background voices (NNA continue) and resonant filters on every channel do local Tracker = require("@formats/codecs/audio/Tracker") local function song(format: string, filter: boolean): any local m = Tracker.newModule(format, 32) m.order = { 0 } m.patterns[1] = Tracker.newPattern(64, 32) local s = Tracker.newSample("saw") s.length = 1000 s.data = buffer.create(4000) for i = 0, 999 do buffer.writef32(s.data, i * 4, (i % 100) / 50 - 1) end s.loopStart, s.loopEnd, s.loopType = 0, 1000, 1 m.samples[1] = s if format == "it" then local ins = Tracker.newInstrument("nna") for n = 1, 120 do ins.sampleMap[n] = 1 end ins.nna = 1 ins.fadeout = 64 if filter then ins.cutoff, ins.resonance = 60, 40 end m.instruments[1] = ins end for ch = 1, 32 do for row = 0, 63, 16 do Tracker.setCell(m, 0, row, ch, 37 + ch + row // 16, 1, 0, 0, 0) end end return m end local function realtime(label: string, m: any, voices: number) local best, frames = math.huge, 0 local out = buffer.create(4096 * 8) for _ = 1, 3 do local dec = Tracker.render(m) :: any frames = 0 local t0 = os.clock() while true do local _, n = dec:read(4096, out) if n == 0 then break end frames += n end best = math.min(best, os.clock() - t0) end print(string.format("%-8s %-30s %8.2f ms %7.1f x realtime %5.1f M voice-samples/s", runtime, label, best * 1000, frames / 44100 / best, voices * frames / best / 1e6)) end realtime("tracker 32 ch (mod)", song("mod", false), 32) realtime("tracker 32 ch + NNA, filters", song("it", true), 64) end do -- 3D (ws-3d): a 400 x 400 grid mesh (160k vertices, 318k triangles) through our own writers, then the readers; a -- 128^3 noise voxel grid through VOX and greedy meshing local Types = require("@formats/Types") local MeshOps = require("@formats/ops/MeshOps") local Gltf = require("@formats/model/gltf") local Obj = require("@formats/model/obj") local Stl = require("@formats/model/stl") local Ply = require("@formats/model/ply") local Vox = require("@formats/model/vox") local N = 400 local pos = Types.Scene.accessor(nil, "f32", 3, N * N) local uv = Types.Scene.accessor(nil, "f32", 2, N * N) for y = 0, N - 1 do for x = 0, N - 1 do local i = y * N + x buffer.writef32(pos.data, i * 12, x / N) buffer.writef32(pos.data, i * 12 + 4, math.sin(x * 0.1) * math.cos(y * 0.1) * 0.05) buffer.writef32(pos.data, i * 12 + 8, y / N) buffer.writef32(uv.data, i * 8, x / N) buffer.writef32(uv.data, i * 8 + 4, y / N) end end local ind = Types.Scene.accessor(nil, "u32", 1, (N - 1) * (N - 1) * 6) local k = 0 for y = 0, N - 2 do for x = 0, N - 2 do local a = y * N + x for _, v in { a, a + N, a + 1, a + 1, a + N, a + N + 1 } do buffer.writeu32(ind.data, k * 4, v) k += 1 end end end local prim = { attributes = { POSITION = pos, TEXCOORD_0 = uv }, indices = ind, mode = "triangles" } :: any MeshOps.computeNormals(prim) local scene = Types.Scene.fromPrimitive(prim, "grid") bench("meshops computeNormals 318k tris", 3, buffer.len(pos.data), function() MeshOps.computeNormals(prim) end) local glb = assert(Gltf.encode(scene, { binary = true })) bench("gltf glb decode (" .. buffer.len(glb) // 1000 .. " KB)", 5, buffer.len(glb), function() Gltf.decode(Bytes.reader(glb)) end) bench("gltf glb encode", 3, buffer.len(glb), function() Gltf.encode(scene, { binary = true }) end) local obj = assert(Obj.encode(scene)) bench("obj decode (" .. buffer.len(obj) // 1000 .. " KB)", 2, buffer.len(obj), function() Obj.decode(Bytes.reader(obj)) end) bench("obj encode", 2, buffer.len(obj), function() Obj.encode(scene) end) local stl = assert(Stl.encode(scene)) bench("stl binary decode (" .. buffer.len(stl) // 1000 .. " KB)", 5, buffer.len(stl), function() Stl.decode(Bytes.reader(stl)) end) local ply = assert(Ply.encode(scene)) bench("ply binary decode (" .. buffer.len(ply) // 1000 .. " KB)", 5, buffer.len(ply), function() Ply.decode(Bytes.reader(ply)) end) local Fbx = require("@formats/model/fbx") local fbx = assert(Fbx.encode(scene)) bench("fbx binary decode (" .. buffer.len(fbx) // 1000 .. " KB)", 3, buffer.len(fbx), function() Fbx.decode(Bytes.reader(fbx)) end) bench("fbx binary encode (zlib arrays)", 2, buffer.len(fbx), function() Fbx.encode(scene) end) bench("fbx binary encode (raw arrays)", 3, buffer.len(fbx), function() Fbx.encode(scene, { compress = false }) end) local fbxa = assert(Fbx.encode(scene, { ascii = true })) bench("fbx ascii decode (" .. buffer.len(fbxa) // 1000 .. " KB)", 2, buffer.len(fbxa), function() Fbx.decode(Bytes.reader(fbxa)) end) local ThreeMf = require("@formats/model/3mf") local tmf = assert(ThreeMf.encode(scene)) bench("3mf decode (" .. buffer.len(tmf) // 1000 .. " KB zipped)", 2, buffer.len(tmf), function() ThreeMf.decode(Bytes.reader(tmf)) end) bench("3mf encode", 2, buffer.len(tmf), function() ThreeMf.encode(scene) end) local Wrl = require("@formats/model/vrml") local X3d = require("@formats/model/x3d") local wrl = assert(Wrl.encode(scene)) bench("vrml decode (" .. buffer.len(wrl) // 1000 .. " KB)", 2, buffer.len(wrl), function() Wrl.decode(Bytes.reader(wrl)) end) bench("vrml encode", 2, buffer.len(wrl), function() Wrl.encode(scene) end) local x3d = assert(X3d.encode(scene)) bench("x3d xml decode (" .. buffer.len(x3d) // 1000 .. " KB)", 2, buffer.len(x3d), function() X3d.decode(Bytes.reader(x3d)) end) local V = 128 local grid = Types.Voxels.new(V, V, V) for z = 0, V - 1 do for y = 0, V - 1 do for x = 0, V - 1 do local h = (math.sin(x * 0.11) + math.cos(y * 0.07) + 2) * V / 8 + z * 0 if z < h then Types.Voxels.set(grid, x, y, z, 1 + (x // 8 + y // 8) % 6) end end end end local vox = assert(Vox.encode(grid)) bench("vox decode (" .. buffer.len(vox) // 1000 .. " KB)", 5, buffer.len(vox), function() Vox.decode(Bytes.reader(vox)) end) bench("greedy mesh 128^3 (MB of cells)", 3, V * V * V, function() MeshOps.voxelsToPrimitive(grid) end) end do -- STEP (tools/fixtures/step.py): the largest case, parse and write local Step = require("@formats/cad/step") local SC = require("@tests/gen/step_cases") local big = SC[1] for _, c in SC do if #c.data > #big.data then big = c end end local data = buffer.fromstring(big.data) local cad = assert(Step.decode(Bytes.reader(data))) bench(string.format("step parse (%.1f MB)", #big.data / 1e6), 3, #big.data, function() Step.decode(Bytes.reader(data)) end) bench("step write", 3, #big.data, function() Step.encode(cad) end) end -- ------------------------------------------------------------------------------------------- ws-video-codecs: fps do local Jpeg = require("@formats/codecs/image/Jpeg") local Mpeg1 = require("@formats/codecs/video/Mpeg1") local Base64 = require("@formats/core/Base64") local Types = require("@formats/Types") local MB = require("@tests/gen/mjpeg_bench") local M1 = require("@tests/gen/mpeg1_bench") -- best of n runs of f (which handles `frames` frames): ms per frame and frames per second local function fps(label: string, n: number, frames: number, f: () -> ()) f() local dt = math.huge for _ = 1, n do local t0 = os.clock() f() dt = math.min(dt, os.clock() - t0) end print(string.format("%-8s %-30s %8.2f ms %7.1f fps", runtime, label, dt * 1000 / frames, frames / dt)) end for _, c in MB.frames do local b = Base64.decode(c.data) :: buffer local img = assert(Jpeg.decode(b, 0, nil, { yuv = true })) assert(Crc32.of(img.pixels) == c.yuv, "mjpeg bench: " .. c.name .. " does not match TurboJPEG") fps("mjpeg decode yuv " .. c.name, 10, 1, function() Jpeg.decode(b, 0, nil, { yuv = true }) end) fps("mjpeg decode rgba " .. c.name, 10, 1, function() Jpeg.decode(b) end) end for _, s in MB.sources do local img = Types.Image.new(s.width, s.height, "yuv420p") img.pixels = assert(Deflate.zlib(Base64.decode(s.yuv) :: buffer)) fps(string.format("mjpeg encode yuv %dx%d q85", s.width, s.height), 5, 1, function() Jpeg.encode(img, { quality = 85 }) end) end -- (LuaJIT also with the trace limits the api sets, host/init.luau: the default 1000 traces thrash on MPEG-1) local function mpeg1(tag: string) for _, s in M1 do local file = Base64.decode(s.file) :: buffer for _, rgba in { false, true } do fps(string.format("mpeg1 decode %s %dx%d%s", if rgba then "rgba" else "yuv", s.width, s.height, tag), 3, #s.units, function() local dec = Mpeg1.new({ reorder = true, rgba = rgba }) for i, u in s.units do dec:decode(file, u[1], u[2], i) end while dec:flush() do end end) end end end jitTune(false) mpeg1("") if runtime == "luajit" then jitTune(true) mpeg1(" (jit tuned)") jitTune(false) end end -- ------------------------------------------------------------------------------------------- ws-video: containers do local F = require("@formats") local VB = require("@tests/gen/videobench") local function clock(n: number, f: () -> number): (number, number) local frames = f() local dt = math.huge for _ = 1, n do local t0 = os.clock() frames = f() dt = math.min(dt, os.clock() - t0) end return dt, frames end for _, c in VB do local data = buffer.fromstring(c.data) local dtOpen = clock(3, function(): number F.video.open(data, { audio = false }) return 1 end) for _, rgba in { false, true } do local ok, dt, frames = pcall(clock, 2, function(): number local v = assert(F.video.open(data, { audio = false, rgba = rgba })) local n = 0 while true do local f, err = v:nextFrame() if not f then assert(err == nil, tostring(err)) break end n += 1 end return n end) if ok then print(string.format("%-8s %-30s %8.2f ms %7.1f fps (open %.1f ms)", runtime, string.format("video %s %s %s", c.size, c.name, if rgba then "rgba" else "yuv"), dt * 1000 / frames, frames / dt, dtOpen * 1000)) else print(string.format("%-8s %-30s %s", runtime, "video " .. c.size .. " " .. c.name, tostring(dt))) end end if c.name == "raw.y4m" then local dt, frames = clock(2, function(): number assert(F.convert(data, "avi", { quality = 85 })) return 8 end) print(string.format("%-8s %-30s %8.2f ms %7.1f fps", runtime, "video " .. c.size .. " y4m -> mjpeg avi", dt * 1000 / frames, frames / dt)) end end end -- ------------------------------------------------------------------------------------------- ws-video-vp8: fps do -- VP8 video (codecs/image/Vp8, tools/fixtures/vp8video.py): whole IVF streams (libvpx, panning testsrc2) through one -- decoder object; frames per second. On LuaJIT the library's host module raises the trace limits (maxtrace=8000, -- see src/Formats/host/init.luau): the second pair of lines runs with them, as the api does. local Vp8 = require("@formats/codecs/image/Vp8") local VB = require("@tests/gen/vp8video_bench") local function run(tag: string) for _, c in VB do local b = buffer.fromstring(c.ivf) local frames = {} local p = 32 while p + 12 <= buffer.len(b) do local n = buffer.readu32(b, p) table.insert(frames, { p + 12, n }) p += 12 + n end local dt = bench(string.format("vp8 decode %dx%d%s", c.width, c.height, tag), 3, c.width * c.height * 1.5 * #frames, function() local dec = Vp8.newDecoder() for _, f in frames do dec:decodeFrame(b, f[1], f[2]) end end) print(string.format("%-8s %-30s %8.1f fps", runtime, " (" .. #frames .. " frames)", #frames / dt)) end end jitTune(false) run("") if runtime == "luajit" then jitTune(true) run(" (jit tuned)") jitTune(false) end end do -- H.264 (codecs/video/H264): whole Annex B streams, frames per second (decode + the cropped yuv420p output copies). The -- testsrc2 clips are easy (mostly static); the mandelbrot zooms move everywhere. LuaJIT runs twice: with its default -- trace limits and with the ones host/init.luau sets (maxtrace=8000, maxmcode=65536). local H264 = require("@formats/codecs/video/H264") local HB = require("@tests/gen/h264_bench") local function run(tag: string) for _, c in HB do local n = c.width * c.height * 3 // 2 * #c.frames local dt = bench(string.format("h264 %s %dx%d%s", c.name, c.width, c.height, tag), 3, n, function() H264.decodeAll(c.data) end) print(string.format("%-8s %-30s %8.1f fps", runtime, " (" .. #c.frames .. " frames)", #c.frames / dt)) end end jitTune(false) run("") if runtime == "luajit" then jitTune(true) run(" (jit tuned)") jitTune(false) end end do -- game formats (ws-game): PKWARE DCL explode (StormLib's implode streams from tools/fixtures/mpq.py), reading every -- file of a StormLib MPQ (MB/s of file data), Freedoom's MAP01 to a Scene (tools/fixtures/wad.py: sector -- outlines, triangulation, walls; MB/s of map lumps), an MD2 with every frame as a morph target local Explode = require("@formats/codecs/compress/Explode") local Mpq = require("@formats/archive/mpq") local Wad = require("@formats/archive/wad") local MQ = require("@tests/gen/mpq") local WD = require("@tests/gen/wad") for _, c in MQ.implode do if c.name == "text" or c.name == "ascii-4096" or c.name == "binary-2048" then local data = buffer.fromstring(c.data) bench("explode " .. c.name .. " (" .. c.size .. " B)", 20, c.size, function() Explode.decompress(data) end) end end local arch = MQ.archives[1] local mb = buffer.fromstring(arch.data) local a = assert(Mpq.decode(Bytes.reader(mb))) local total = 0 for _, e in a:list() do total += e.size end bench("mpq read every file (v1)", 5, total, function() local m = Mpq.decode(Bytes.reader(mb)) for _, e in m:list() do m:read(e.name) end end) local wb = buffer.fromstring(WD.freedoom.data) local w = assert(Wad.decode(Bytes.reader(wb))) local lumps = 0 for _, l in Wad.lumps(w) :: any do if l.map == "MAP01" then lumps += l.size end end bench("wad MAP01 -> Scene (no textures)", 3, lumps, function() Wad.map(w, "MAP01", { textures = false }) end) end do -- Draco (codecs/model/Draco): the Stanford bunny (35k points, 69k faces, Edgebreaker valence, normals) and a UV -- sphere with seams; MB/s of decoded output (u32 indices + f32 attributes per point), plus triangles per second. local Draco = require("@formats/codecs/model/Draco") local DC = require("@tests/gen/draco_cases") for _, c in DC do if c.name == "enc/bunny_norm.obj.cl7" or c.name == "enc/uvsphere.obj.cl10" or c.name == "enc/uvsphere.obj.cl0" then local data = buffer.fromstring(c.data) local g = assert(Draco.decode(data)) local n = g.numFaces * 12 for _, a in g.attributes do n += buffer.len(a.data) end local dt = bench("draco " .. string.sub(c.name, 5), 3, n, function() Draco.decode(data) end) print(string.format("%-8s %-30s %8.0f triangles/s", runtime, " (" .. g.numFaces .. " faces)", g.numFaces / dt)) end end end do -- NBT / voxels (ws-voxel): a chunk-like NBT tree (24 sections with packed long arrays, 4000 entity-like compounds) -- through codecs/text/Nbt (binary and SNBT), 1M packed 5-bit indices, a 64^3 Sponge schematic and Qubicle file local Nbt = require("@formats/codecs/text/Nbt") local Mc = require("@formats/codecs/model/Minecraft") local Schematic = require("@formats/model/schematic") local Qb = require("@formats/model/qb") local sections = Nbt.list("compound") for s = 1, 24 do local pal = Nbt.list("compound") for p = 1, 16 do table.insert(pal, Nbt.compound({ Name = "minecraft:block_" .. p, Properties = Nbt.compound({ axis = "y" }, { "axis" }) }, { "Name", "Properties" })) end local longs = buffer.create(256 * 8) for i = 0, 511 do buffer.writeu32(longs, i * 4, (i * 2654435761) % 4294967296) end table.insert(sections, Nbt.compound({ Y = Nbt.byte(s - 5), block_states = Nbt.compound({ palette = pal, data = Nbt.longArray(longs) }, { "palette", "data" }) }, { "Y", "block_states" })) end local ents = Nbt.list("compound") for i = 1, 4000 do table.insert(ents, Nbt.compound({ id = "minecraft:thing", Pos = Nbt.list("double", { Nbt.double(i * 0.5), Nbt.double(64), Nbt.double(-i * 0.25) }), Health = Nbt.float(20), UUID = Nbt.intArray({ i, -i, i * 3, 7 }), Tags = Nbt.list("string", { "a", "b" }), Age = Nbt.short(i % 1000), Seed = Nbt.long(i * 1234567), }, { "id", "Pos", "Health", "UUID", "Tags", "Age", "Seed" })) end local root = Nbt.compound({ DataVersion = 3953, sections = sections, entities = ents }, { "DataVersion", "sections", "entities" }) local raw = assert(Nbt.encode(root, { compression = "none" })) bench("nbt decode (" .. buffer.len(raw) // 1000 .. " KB)", 5, buffer.len(raw), function() Nbt.decode(raw) end) bench("nbt encode", 5, buffer.len(raw), function() Nbt.encode(root, { compression = "none" }) end) local text = assert(Nbt.print(root)) bench("snbt parse (" .. #text // 1000 .. " KB)", 3, #text, function() Nbt.parse(text) end) bench("snbt print", 3, #text, function() Nbt.print(root) end) local n = 1048576 local idx = buffer.create(n * 2) for i = 0, n - 1 do buffer.writeu16(idx, i * 2, (i * 7) % 32) end local packed = Mc.Packed.pack(idx, n, 5, false) local out = buffer.create(n * 2) bench("packed unpack 1M x 5 bits (MB out)", 5, n * 2, function() Mc.Packed.unpack(packed, 5, n, false, out, 32) end) local V = 64 local states = { "minecraft:air" } for i = 1, 40 do table.insert(states, "minecraft:block_" .. i) end local cells = buffer.create(V * V * V * 2) for i = 0, V * V * V - 1 do buffer.writeu16(cells, i * 2, if (i // V) % 3 == 0 then 0 else 1 + (i // 97) % 40) end local grid = Mc.voxels(V, V, V, states, cells) local schem = assert(Schematic.encode(grid, { compression = "none" })) bench("schem decode 64^3 (MB of cells)", 3, V * V * V, function() Schematic.decode(Bytes.reader(schem)) end) bench("schem encode 64^3", 3, V * V * V, function() Schematic.encode(grid, { compression = "none" }) end) local qb = assert(Qb.encode(grid)) bench("qb decode 64^3 rle (MB of cells)", 3, V * V * V, function() Qb.decode(Bytes.reader(qb)) end) end -- ------------------------------------------------------------------------------------------- ws-video-codecs: fps do local Jpeg = require("@formats/codecs/image/Jpeg") local Mpeg1 = require("@formats/codecs/video/Mpeg1") local Base64 = require("@formats/core/Base64") local Types = require("@formats/Types") local MB = require("@tests/gen/mjpeg_bench") local M1 = require("@tests/gen/mpeg1_bench") -- best of n runs of f (which handles `frames` frames): ms per frame and frames per second local function fps(label: string, n: number, frames: number, f: () -> ()) f() local dt = math.huge for _ = 1, n do local t0 = os.clock() f() dt = math.min(dt, os.clock() - t0) end print(string.format("%-8s %-30s %8.2f ms %7.1f fps", runtime, label, dt * 1000 / frames, frames / dt)) end for _, c in MB.frames do local b = Base64.decode(c.data) :: buffer local img = assert(Jpeg.decode(b, 0, nil, { yuv = true })) assert(Crc32.of(img.pixels) == c.yuv, "mjpeg bench: " .. c.name .. " does not match TurboJPEG") fps("mjpeg decode yuv " .. c.name, 10, 1, function() Jpeg.decode(b, 0, nil, { yuv = true }) end) fps("mjpeg decode rgba " .. c.name, 10, 1, function() Jpeg.decode(b) end) end for _, s in MB.sources do local img = Types.Image.new(s.width, s.height, "yuv420p") img.pixels = assert(Deflate.zlib(Base64.decode(s.yuv) :: buffer)) fps(string.format("mjpeg encode yuv %dx%d q85", s.width, s.height), 5, 1, function() Jpeg.encode(img, { quality = 85 }) end) end -- (LuaJIT also with the trace limits the api sets, host/init.luau: the default 1000 traces thrash on MPEG-1) local function mpeg1(tag: string) for _, s in M1 do local file = Base64.decode(s.file) :: buffer for _, rgba in { false, true } do fps(string.format("mpeg1 decode %s %dx%d%s", if rgba then "rgba" else "yuv", s.width, s.height, tag), 3, #s.units, function() local dec = Mpeg1.new({ reorder = true, rgba = rgba }) for i, u in s.units do dec:decode(file, u[1], u[2], i) end while dec:flush() do end end) end end end -- MPEG-2: 720x576 interlaced (field prediction / field DCT, B-frames), as on a DVD (ws-video2) local M2 = require("@tests/gen/mpeg2_bench") local function mpeg2(tag: string) for _, s in M2 do local file = Base64.decode(s.file) :: buffer fps(string.format("mpeg2 decode yuv %dx%d interlaced%s", s.width, s.height, tag), 3, #s.units, function() local dec = Mpeg1.new({ reorder = true, rgba = false }) for i, u in s.units do dec:decode(file, u[1], u[2], i) end while dec:flush() do end end) end end jitTune(false) mpeg1("") mpeg2("") if runtime == "luajit" then jitTune(true) mpeg1(" (jit tuned)") mpeg2(" (jit tuned)") jitTune(false) end end do -- ------------------------------------------------------------------------------------- ws-video2-theora: fps -- Theora (codecs/video/Theora): 320x240 clips, 50 frames, keyframe every 25: testsrc2 at 600 kbit/s (mostly static: -- few coded blocks) and a mandelbrot zoom at 1200 kbit/s (every block coded, moving); decode alone and decode + -- image() (the yuv420p copy every VideoDecoder frame makes) local Theora = require("@formats/codecs/video/Theora") local Ogg = require("@formats/containers/Ogg") local Base64 = require("@formats/core/Base64") local TB = require("@tests/gen/theora_bench") local function run(tag: string) for _, c in TB do local d = Ogg.open(Base64.decode(c.file) :: buffer) local hdrs, data = {}, {} for p in d:packets(d:find("theora")) do table.insert(if #hdrs < 3 then hdrs else data, Ogg.copy(p)) end for _, image in { false, true } do local n = c.width * c.height * 3 // 2 * #data local dt = bench(string.format("theora %s %dx%d%s%s", c.name, c.width, c.height, if image then " +img" else "", tag), 3, n, function() local dec = Theora.new(hdrs) :: any for _, p in data do dec:decode(p) if image then dec:image() end end end) print(string.format("%-8s %-30s %8.1f fps", runtime, " (" .. #data .. " frames)", #data / dt)) end end end jitTune(false) run("") if runtime == "luajit" then jitTune(true) run(" (jit tuned)") jitTune(false) end end -- ------------------------------------------------------------------------------------------- ws-video2-legacy: fps do -- the legacy codecs (codecs/video/Legacy) through F.video.open, rgba8 frames out: ffmpeg's encoders at 320x240 -- (tools/fixtures/legacy.py), a 320x200 FLC (fli.py) and a 320x200 SMK4 (smk.py, textured: mostly FULL blocks); -- frames per second of the whole decode (and the Smacker audio track, seconds of audio per second) local F = require("@formats") local LB = require("@tests/gen/legacy_bench") local cases = table.clone(LB) table.insert(cases, { name = "fli.flc", data = require("@tests/gen/fli_bench").data, width = 320, height = 200 }) table.insert(cases, { name = "smk4.smk", data = require("@tests/gen/smk_bench").data, width = 320, height = 200 }) for _, c in cases do local data = buffer.fromstring(c.data) local frames = 0 local dt = math.huge for _ = 1, 3 do local t0 = os.clock() local v = assert(F.video.open(data, { audio = false })) frames = 0 while v:nextFrame() do frames += 1 end dt = math.min(dt, os.clock() - t0) end print(string.format("%-8s %-30s %8.2f ms %7.1f fps", runtime, string.format("legacy %s %dx%d", c.name, c.width, c.height), dt * 1000 / frames, frames / dt)) end local v = assert(F.video.open(buffer.fromstring(require("@tests/gen/smk_bench").data))) local a = assert(v.audio) local t0 = os.clock() local n = 0 while true do local _, got = a:read(4096) if got == 0 then break end n += got end local dt = os.clock() - t0 print(string.format("%-8s %-30s %8.2f ms %7.1fx real time", runtime, "smacker audio 22 kHz stereo", dt * 1000, n / a.sampleRate / dt)) end do -- 3D (ws-3d): a 400 x 400 grid mesh (160k vertices, 318k triangles) through our own writers, then the readers; a -- 128^3 noise voxel grid through VOX and greedy meshing local Types = require("@formats/Types") local MeshOps = require("@formats/ops/MeshOps") local Gltf = require("@formats/model/gltf") local Obj = require("@formats/model/obj") local Stl = require("@formats/model/stl") local Ply = require("@formats/model/ply") local Vox = require("@formats/model/vox") local N = 400 local pos = Types.Scene.accessor(nil, "f32", 3, N * N) local uv = Types.Scene.accessor(nil, "f32", 2, N * N) for y = 0, N - 1 do for x = 0, N - 1 do local i = y * N + x buffer.writef32(pos.data, i * 12, x / N) buffer.writef32(pos.data, i * 12 + 4, math.sin(x * 0.1) * math.cos(y * 0.1) * 0.05) buffer.writef32(pos.data, i * 12 + 8, y / N) buffer.writef32(uv.data, i * 8, x / N) buffer.writef32(uv.data, i * 8 + 4, y / N) end end local ind = Types.Scene.accessor(nil, "u32", 1, (N - 1) * (N - 1) * 6) local k = 0 for y = 0, N - 2 do for x = 0, N - 2 do local a = y * N + x for _, v in { a, a + N, a + 1, a + 1, a + N, a + N + 1 } do buffer.writeu32(ind.data, k * 4, v) k += 1 end end end local prim = { attributes = { POSITION = pos, TEXCOORD_0 = uv }, indices = ind, mode = "triangles" } :: any MeshOps.computeNormals(prim) local scene = Types.Scene.fromPrimitive(prim, "grid") bench("meshops computeNormals 318k tris", 3, buffer.len(pos.data), function() MeshOps.computeNormals(prim) end) local glb = assert(Gltf.encode(scene, { binary = true })) bench("gltf glb decode (" .. buffer.len(glb) // 1000 .. " KB)", 5, buffer.len(glb), function() Gltf.decode(Bytes.reader(glb)) end) bench("gltf glb encode", 3, buffer.len(glb), function() Gltf.encode(scene, { binary = true }) end) local obj = assert(Obj.encode(scene)) bench("obj decode (" .. buffer.len(obj) // 1000 .. " KB)", 2, buffer.len(obj), function() Obj.decode(Bytes.reader(obj)) end) bench("obj encode", 2, buffer.len(obj), function() Obj.encode(scene) end) local stl = assert(Stl.encode(scene)) bench("stl binary decode (" .. buffer.len(stl) // 1000 .. " KB)", 5, buffer.len(stl), function() Stl.decode(Bytes.reader(stl)) end) local ply = assert(Ply.encode(scene)) bench("ply binary decode (" .. buffer.len(ply) // 1000 .. " KB)", 5, buffer.len(ply), function() Ply.decode(Bytes.reader(ply)) end) local Fbx = require("@formats/model/fbx") local fbx = assert(Fbx.encode(scene)) bench("fbx binary decode (" .. buffer.len(fbx) // 1000 .. " KB)", 3, buffer.len(fbx), function() Fbx.decode(Bytes.reader(fbx)) end) bench("fbx binary encode (zlib arrays)", 2, buffer.len(fbx), function() Fbx.encode(scene) end) bench("fbx binary encode (raw arrays)", 3, buffer.len(fbx), function() Fbx.encode(scene, { compress = false }) end) local fbxa = assert(Fbx.encode(scene, { ascii = true })) bench("fbx ascii decode (" .. buffer.len(fbxa) // 1000 .. " KB)", 2, buffer.len(fbxa), function() Fbx.decode(Bytes.reader(fbxa)) end) local ThreeMf = require("@formats/model/3mf") local tmf = assert(ThreeMf.encode(scene)) bench("3mf decode (" .. buffer.len(tmf) // 1000 .. " KB zipped)", 2, buffer.len(tmf), function() ThreeMf.decode(Bytes.reader(tmf)) end) bench("3mf encode", 2, buffer.len(tmf), function() ThreeMf.encode(scene) end) local V = 128 local grid = Types.Voxels.new(V, V, V) for z = 0, V - 1 do for y = 0, V - 1 do for x = 0, V - 1 do local h = (math.sin(x * 0.11) + math.cos(y * 0.07) + 2) * V / 8 + z * 0 if z < h then Types.Voxels.set(grid, x, y, z, 1 + (x // 8 + y // 8) % 6) end end end end local vox = assert(Vox.encode(grid)) bench("vox decode (" .. buffer.len(vox) // 1000 .. " KB)", 5, buffer.len(vox), function() Vox.decode(Bytes.reader(vox)) end) bench("greedy mesh 128^3 (MB of cells)", 3, V * V * V, function() MeshOps.voxelsToPrimitive(grid) end) end do -- textures (ws-tex): codecs/image/Bcn on a 256 x 256 image (tools/fixtures/bcn.py); MB/s of rgba8 output (decode) -- or input (encode); BC6H of rgbaf32 output local Bcn = require("@formats/codecs/image/Bcn") local BB = require("@tests/gen/bcn_bench") local w, h = BB.w, BB.h local px = buffer.fromstring(BB.rgba) for _, kind in { "bc1", "bc3", "bc5" } do local blocks = Bcn.encode(kind, px, w, h) :: buffer bench("bcn decode " .. kind .. " 256x256", 5, w * h * 4, function() Bcn.decode(kind, blocks, 0, w, h) end) bench("bcn encode " .. kind .. " 256x256", 2, w * h * 4, function() Bcn.encode(kind, px, w, h) end) end local b7, b6 = buffer.fromstring(BB.bc7), buffer.fromstring(BB.bc6h) bench("bcn decode bc7 256x256", 5, w * h * 4, function() Bcn.decode("bc7", b7, 0, w, h) end) bench("bcn decode bc6h 256x256", 5, w * h * 16, function() Bcn.decode("bc6h", b6, 0, w, h) end) end do -- OpenEXR (ws-tex): a 512 x 256 half RGBA image from the OpenEXR bindings (tools/fixtures/exr.py), ZIP and PIZ; -- MB/s of rgbaf32 output; our ZIP encoder on the decoded floats local Exr = require("@formats/image/exr") local EB = require("@tests/gen/exr_bench") local n = 512 * 256 * 16 for _, k in { "zip", "piz" } do local data = buffer.fromstring(EB[k]) bench("exr decode " .. k .. " 512x256 half", 3, n, function() Exr.decode(Bytes.reader(data), { native = true }) end) end local img = Exr.decode(Bytes.reader(buffer.fromstring(EB.zip)), { native = true }) :: any bench("exr encode zip 512x256 half", 2, n, function() Exr.encode(img) end) end -- ------------------------------------------------------------------------------------------- ws-video2-legacy: fps do -- the legacy codecs (codecs/video/Legacy) through F.video.open, rgba8 frames out: ffmpeg's encoders at 320x240 -- (tools/fixtures/legacy.py), a 320x200 FLC (fli.py) and a 320x200 SMK4 (smk.py, textured: mostly FULL blocks); -- frames per second of the whole decode (and the Smacker audio track, seconds of audio per second) local F = require("@formats") local LB = require("@tests/gen/legacy_bench") local cases = table.clone(LB) table.insert(cases, { name = "fli.flc", data = require("@tests/gen/fli_bench").data, width = 320, height = 200 }) table.insert(cases, { name = "smk4.smk", data = require("@tests/gen/smk_bench").data, width = 320, height = 200 }) for _, c in cases do local data = buffer.fromstring(c.data) local frames = 0 local dt = math.huge for _ = 1, 3 do local t0 = os.clock() local v = assert(F.video.open(data, { audio = false })) frames = 0 while v:nextFrame() do frames += 1 end dt = math.min(dt, os.clock() - t0) end print(string.format("%-8s %-30s %8.2f ms %7.1f fps", runtime, string.format("legacy %s %dx%d", c.name, c.width, c.height), dt * 1000 / frames, frames / dt)) end local v = assert(F.video.open(buffer.fromstring(require("@tests/gen/smk_bench").data))) local a = assert(v.audio) local t0 = os.clock() local n = 0 while true do local _, got = a:read(4096) if got == 0 then break end n += got end local dt = os.clock() - t0 print(string.format("%-8s %-30s %8.2f ms %7.1fx real time", runtime, "smacker audio 22 kHz stereo", dt * 1000, n / a.sampleRate / dt)) end -- ws-audio2: chip/midi do -- AHX / HVL (codecs/audio/Hively): a whole song rendered at 44.1 kHz (tools/fixtures/ahx.py karma.ahx, 3 s; hvl.py -- the 6-channel demo with ring modulation); MB/s of stereo f32 output, and how many times faster than real time local Ahx, Hvl = require("@formats/music/ahx"), require("@formats/music/hvl") local AC, HC = require("@tests/gen/ahx_cases"), require("@tests/gen/hvl_cases") for _, spec in { { Ahx, AC, "karma.ahx", "ahx render karma (4 ch)" }, { Hvl, HC, "demo", "hvl render demo (6 ch)" } } do for _, c in spec[2] do if c.name == spec[3] then local song = assert(spec[1].decode(Bytes.reader(buffer.fromstring(c.data)))) local frames = 0 local dt = bench(spec[4], 3, c.frames * 8, function() local dec = song:render({ maxDuration = c.maxDuration }) frames = dec.frames dec:read(frames) end) print(string.format("%-8s %-30s %8.1f x real time", runtime, "", frames / 44100 / dt)) end end end end -- ws-audio2: lossy do -- Musepack (codecs/audio/Musepack) SV8 / SV7 and AC-3 5.1 (codecs/audio/Ac3): whole-file decodes, MB/s of f32 output -- (tools/fixtures/mpc.py: 1.2 s of 44.1 kHz stereo at quality 5; tools/fixtures/ac3.py: 0.16 s of 48 kHz 5.1 at -- 448 kbps, decoded 4 times per run) local Mpc = require("@formats/audio/mpc") local MpcFx = require("@tests/gen/mpc_cases") local Ac3F = require("@formats/audio/ac3") local Ac3Fx = require("@tests/gen/ac3_cases") for _, c in MpcFx do if c.name == "sv8_q5_stereo" or c.name == "sv7_q5_stereo" then local b = buffer.fromstring(c.data) bench("mpc " .. c.name, 5, c.frames * c.channels * 4, function() assert(Mpc.decode(Bytes.reader(b))) end) end end for _, c in Ac3Fx do if c.name == "5.1_448" then local b = buffer.fromstring(c.data) bench("ac3 5.1 448 kbps", 5, c.frames * c.channels * 4 * 4, function() for _ = 1, 4 do assert(Ac3F.decode(Bytes.reader(b))) end end) end end end -- ws-audio2: adpcm / qoa do -- codecs/audio/Adpcm (IMA nibble stream, Nintendo DSP frames) and QOA decode / encode, over generated signals; MB/s -- of f32 output (MB/s of input for the encoder) local Adpcm = require("@formats/codecs/audio/Adpcm") local QoaCodec = require("@formats/codecs/audio/Qoa") local Qoa = require("@formats/audio/qoa") local n = 44100 * 5 local sig = Types.Audio.new(44100, 2, n) for i = 0, n - 1 do local t = i / 44100 buffer.writef32(sig.samples, i * 8, 0.5 * math.sin(2 * math.pi * 440 * t) + 0.1 * math.sin(2 * math.pi * 3000 * t)) buffer.writef32(sig.samples, i * 8 + 4, 0.4 * math.sin(2 * math.pi * 660 * t + 1)) end -- IMA: encode the left channel as a nibble stream, then decode it local ima = buffer.create(n // 2) Adpcm.imaEncode(sig.samples, 0, 2, n, buffer.create(8), 0, ima, 0, 0, 1, false) local out = buffer.create(n * 4) bench("adpcm ima decode", 5, n * 4, function() Adpcm.ima(ima, 0, 0, 1, n, false, buffer.create(8), 0, out, 0, 1) end) -- DSP: random frames with 8 coefficient pairs local frames = n // 14 local dsp = buffer.create(frames * 8) local seed = 1 for i = 0, frames * 8 - 1 do seed = (seed * 1103515245 + 12345) % 2147483648 local v = seed // 65536 % 256 buffer.writeu8(dsp, i, if i % 8 == 0 then (v % 8) * 16 + v % 12 else v) end local coefs = buffer.create(64) for k = 0, 7 do buffer.writei32(coefs, k * 8, 1800 + k * 200) buffer.writei32(coefs, k * 8 + 4, -900 - k * 100) end bench("adpcm dsp decode", 5, frames * 14 * 4, function() Adpcm.dsp(dsp, 0, frames * 14, coefs, 0, buffer.create(8), 0, out, 0, 1) end) -- QOA (stereo 44.1 kHz) local file = assert(Qoa.encode(sig)) bench("qoa encode", 2, n * 2 * 4, function() Qoa.encode(sig) end) local pcm = buffer.create(QoaCodec.FRAME_LEN * 2 * 4) bench("qoa decode", 5, n * 2 * 4, function() local p = 8 while p < buffer.len(file) do local _, size = QoaCodec.decodeFrame(file, p, buffer.len(file) - p, pcm, 0) p += size :: number end end) bench("qoa decode (F.load path)", 5, n * 2 * 4, function() Qoa.decode(Bytes.reader(file)) end) end -- ws-audio2: lossless do -- WavPack / Monkey's Audio / TTA decoders (tools/fixtures/wavpack.py, ape.py, tta.py): MB/s of f32 output local function lossless(label: string, mod: any, data: string) local b = buffer.fromstring(data) local dec = assert(mod.open(Bytes.reader(b))) bench(label, 5, dec.frames * dec.channels * 4, function() mod.decode(Bytes.reader(b)) end) end local Wv = require("@formats/audio/wavpack") for _, c in require("@tests/gen/wavpack_cases") do if c.name == "s16_long" or c.name == "s16_hh" or c.name == "s24_hh" or c.name == "f32" or c.name == "hyb_b3" then lossless("wavpack " .. c.name, Wv, c.data) end end local ApeF = require("@formats/audio/ape") for _, c in require("@tests/gen/ape_cases") do if c.name == "s16_long" or c.name == "s16_long_c4000" or c.name == "s16_c5000" or c.name == "s24" or c.name == "s16_c1000" then lossless("ape " .. c.name, ApeF, c.data) end end local TtaF = require("@formats/audio/tta") for _, c in require("@tests/gen/tta_cases") do if c.name == "s16_long" or c.name == "s24" or c.name == "ch6" then lossless("tta " .. c.name, TtaF, c.data) end end end -- ws-audio2: trackers do -- the other tracker loaders on the shared engine: a 669 (Hz periods, auto slides) and an MMD1 (hold / decay -- envelopes, instruments) from tools/fixtures/{669,med}.py, decoded and rendered at 44.1 kHz local Six69 = require("@formats/music/669") local Med = require("@formats/music/med") local songs = { { Six69, require("@tests/gen/669_cases")[1].data }, { Med, require("@tests/gen/med_cases")[2].data } } local best, frames = math.huge, 0 local out = buffer.create(4096 * 8) for _ = 1, 3 do frames = 0 local t0 = os.clock() for _, s in songs do local dec = (s[1].decode(Bytes.reader(buffer.fromstring(s[2]))) :: any):render() while true do local _, n = dec:read(4096, out) if n == 0 then break end frames += n end end best = math.min(best, os.clock() - t0) end print(string.format("%-8s %-30s %8.2f ms %7.1f x realtime", runtime, "render 669 / med", best * 1000, frames / 44100 / best)) end -- ------------------------------------------------------------------------------------------- ws-video2-flv: fps do -- H.263 / Sorenson Spark (codecs/video/H263, tools/fixtures/h263.py): CIF mandelbrot zooms (1 Mbit/s, an I picture -- every 12), one picture per decode, planes only (frameImage copies excluded) and with the yuv420p Image copies local H263 = require("@formats/codecs/video/H263") local Base64 = require("@formats/core/Base64") local HB = require("@tests/gen/h263_bench") local function run(tag: string) for _, c in HB do local file = Base64.decode(c.file) :: buffer for _, images in { false, true } do local n = #c.units local dt = bench(string.format("%s %dx%d%s%s", c.name, c.width, c.height, if images then " +img" else "", tag), 3, c.width * c.height * 3 // 2 * n, function() local dec = H263.new({ flv = c.flv }) for _, u in c.units do if images then dec:image(file, u[1], u[2]) else dec:decode(file, u[1], u[2]) end end end) print(string.format("%-8s %-30s %8.1f fps", runtime, " (" .. n .. " frames)", n / dt)) end end end jitTune(false) run("") if runtime == "luajit" then jitTune(true) run(" (jit tuned)") jitTune(false) end end