Skip to content

Instantly share code, notes, and snippets.

@manzt
Created March 10, 2025 03:26
Show Gist options
  • Save manzt/2337d6e131a78c20ffb4c8196de0b419 to your computer and use it in GitHub Desktop.
Save manzt/2337d6e131a78c20ffb4c8196de0b419 to your computer and use it in GitHub Desktop.

Revisions

  1. manzt created this gist Mar 10, 2025.
    34 changes: 34 additions & 0 deletions decompression-stream-bench.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    import * as assert from "jsr:@std/[email protected]";
    import * as fflate from "npm:[email protected]";
    import * as pako from "npm:[email protected]";

    const base = new URL(
    "https://raw.githubusercontent.com/zarr-developers/zarr_implementations/5dc998ac72/examples/zarr.zr/gzip/.zarray",
    );

    const BYTES = await fetch(new URL("0.0.0", base))
    .then((r) => r.arrayBuffer())
    .then((b) => new Uint8Array(b));

    const REFERENCE = fflate.gunzipSync(BYTES);

    Deno.bench("DecompressionStream", { baseline: true }, async () => {
    const compressedResponse = new Response(BYTES);
    const decompressedResponse = new Response(
    compressedResponse.body!.pipeThrough(
    new DecompressionStream("gzip"),
    ),
    );
    const buffer = await decompressedResponse.arrayBuffer();
    assert.assert(new Uint8Array(buffer).length === REFERENCE.length);
    });

    Deno.bench("fflate.gunzip", () => {
    const result = fflate.gunzipSync(BYTES);
    assert.assert(result.length === REFERENCE.length);
    });

    Deno.bench("pako.inflate", () => {
    const result = pako.inflate(BYTES);
    assert.assert(result.length === REFERENCE.length);
    });