Skip to content

Commit

Permalink
Benchmark 1gb file
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Feb 21, 2024
1 parent 92cece7 commit 8f5c1d3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hyspappy.wasm.base64: hysnappy.wasm

hysnappy.wasm: snappy.c wasm.c
clang --target=wasm32 \
-O3 \
-O3 -msimd128 \
-nostdlib \
-Wl,--export-all \
-Wl,--no-entry \
Expand Down
28 changes: 28 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import { compress, uncompress } from 'snappyjs'
import { snappyUncompress as uncompressWasm } from '../hysnappy.js'

const fileSize = 200_000_000

const compressed = await time(`generate and compress ${fileSize.toLocaleString()}`, () => {
// Generate input array with random data
const input = new Uint8Array(fileSize)
for (let i = 0; i < fileSize; i++) {
input[i] = Math.floor(Math.random() * 128)
}
return compress(input)
})

const output = new Uint8Array(fileSize)

await time('uncompress wasm', () => uncompressWasm(compressed, output))

// await time('uncompress snappyjs', () => uncompress(compressed, output))

async function time(name, fn) {
const start = performance.now()
const output = await fn()
const ms = performance.now() - start
console.log(`${name} took ${ms} ms`)
return output
}
2 changes: 1 addition & 1 deletion hysnappy.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ function instantiateWasm() {
}

// Base64 encoded hysnappy.wasm
const wasm64 = 'AGFzbQEAAAABEANgAABgA39/fwF/YAF/AX8DBgUAAQEBAgUDAQACBj8KfwFBoIwEC38AQYAIC38AQaAMC38AQaAMC38AQaCMBAt/AEGACAt/AEGgjAQLfwBBgIAIC38AQQALfwBBAQsHwQEOBm1lbW9yeQIAEV9fd2FzbV9jYWxsX2N0b3JzAAAGbWVtY3B5AAEHbWVtbW92ZQACCnVuY29tcHJlc3MAAwxfX2Rzb19oYW5kbGUDAQpfX2RhdGFfZW5kAwILX19zdGFja19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gIEIAFBCGohASAEQQhqIQQgB0F4aiIHQQhLDQALCyAAIApqIQAgAygCCCAFIAtqIgFrQQRKDQEgAyABNgIEIAMQhICAgABFDQILIAMoAgQhAQwACwsgAygCACIBIAEoAgQgAygCDCIEazYCBCABIAQgASgCAGo2AgACQCADLQAQDQBBfiEEDAELQQBBfSAIIABGGyEECyADQSBqJICAgIAAIAQLtgMBB38CQCAAKAIEIgEgACgCCCICRw0AIAAoAgAiAiACKAIAIgMgACgCDCIEaiIBNgIAIAJBBGoiAiACKAIAIgIgBGsiBTYCACAAIAU2AgwCQCACIARHDQAgAEEBOgAQQQAPCyAAIAMgAmoiAjYCCAsCQAJAAkAgAiABayICIAEtAABBAXRBoIiAgABqLwEAQQt2QQFqIgVPDQAgAEERaiABIAIQgoCAgAAhBiAAKAIMIQRBACEHIABBADYCDCAAKAIAIgEgASgCBCAEazYCBCABIAQgASgCAGoiAzYCAANAIAFBBGooAgAiAUUNAyAGIAJqIAMgBSACayIEIAEgBCABSRsiBBCBgICAABogACgCACIBIAEoAgQgBGs2AgQgASABKAIAIARqIgM2AgAgBCACaiICIAVJDQALIAAgBjYCBCAAIAYgBWo2AggMAQsCQCACQQRLDQAgACAAQRFqIAEgAhCCgICAACIBIAJqNgIIIAAgATYCBCAAKAIMIQIgAEEANgIMIAAoAgAiASABKAIEIAJrNgIEIAEgAiABKAIAajYCAAwBCyAAIAE2AgQLQQEhBwsgBwsLqAQBAEGACAugBAAAAAD/AAAA//8AAP///wD/////AAAAAAAAAAAAAAAAAQAECAEQASACAAUIAhACIAMABggDEAMgBAAHCAQQBCAFAAgIBRAFIAYACQgGEAYgBwAKCAcQByAIAAsICBAIIAkABAkJEAkgCgAFCQoQCiALAAYJCxALIAwABwkMEAwgDQAICQ0QDSAOAAkJDhAOIA8ACgkPEA8gEAALCRAQECARAAQKERARIBIABQoSEBIgEwAGChMQEyAUAAcKFBAUIBUACAoVEBUgFgAJChYQFiAXAAoKFxAXIBgACwoYEBggGQAECxkQGSAaAAULGhAaIBsABgsbEBsgHAAHCxwQHCAdAAgLHRAdIB4ACQseEB4gHwAKCx8QHyAgAAsLIBAgICEABAwhECEgIgAFDCIQIiAjAAYMIxAjICQABwwkECQgJQAIDCUQJSAmAAkMJhAmICcACgwnECcgKAALDCgQKCApAAQNKRApICoABQ0qECogKwAGDSsQKyAsAAcNLBAsIC0ACA0tEC0gLgAJDS4QLiAvAAoNLxAvIDAACw0wEDAgMQAEDjEQMSAyAAUOMhAyIDMABg4zEDMgNAAHDjQQNCA1AAgONRA1IDYACQ42EDYgNwAKDjcQNyA4AAsOOBA4IDkABA85EDkgOgAFDzoQOiA7AAYPOxA7IDwABw88EDwgAQgIDz0QPSABEAkPPhA+IAEYCg8/ED8gASALD0AQQCAAZARuYW1lAT0FABFfX3dhc21fY2FsbF9jdG9ycwEGbWVtY3B5AgdtZW1tb3ZlAwp1bmNvbXByZXNzBApyZWZpbGxfdGFnBxIBAA9fX3N0YWNrX3BvaW50ZXIJCgEABy5yb2RhdGEAMglwcm9kdWNlcnMBDHByb2Nlc3NlZC1ieQEMVWJ1bnR1IGNsYW5nCzE2LjAuNiAoMTUpADUPdGFyZ2V0X2ZlYXR1cmVzAysPbXV0YWJsZS1nbG9iYWxzKwhzaWduLWV4dCsHc2ltZDEyOA=='
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"eslint": "8.56.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsdoc": "48.1.0",
"snappyjs": "0.7.0",
"vitest": "1.3.1"
}
}

0 comments on commit 8f5c1d3

Please sign in to comment.