Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compression algorithm benchmarks #271

Open
jsumners-nr opened this issue Dec 31, 2024 · 4 comments
Open

Add compression algorithm benchmarks #271

jsumners-nr opened this issue Dec 31, 2024 · 4 comments

Comments

@jsumners-nr
Copy link

I think it would be helpful to include benchmarks for the common compression algorithms that zlib supports. In particular, I would like to see the comparison between deflate and gzip. Some sort of "large" JSON representation should be used for the test. https://github.com/matthewreagan/WebstersEnglishDictionary/blob/master/dictionary.json may be too large, but something at least a couple of megabytes.

@RafaelGSS
Copy link
Owner

SGTM

@jsumners-nr
Copy link
Author

I'm not sure this is going to work. I added a compression.mjs script like so:

import { fileURLToPath } from 'node:url'
import fs from 'node:fs'
import zlib from 'node:zlib'
import { createBenchmarkSuite } from '../common.mjs'

const fixturePath = fileURLToPath(
  new URL('./fixtures/words_dictionary.json.gz', import.meta.url)
)
let fixtureData = fs.readFileSync(fixturePath)
fixtureData = zlib.gunzipSync(fixtureData)

const suite = createBenchmarkSuite('Compression algorithms')

suite
  .add('Deflate', function () {
    zlib.deflateSync(fixtureData)
  })
  .add('Gzip', function () {
    zlib.gzipSync(fixtureData)
  })

await suite.runAndPrintResults()

With the fixture data coming from https://github.com/dwyl/english-words/blob/master/words_dictionary.json (I gzip -9 that file to keep the repo size down).

The result is always:

❯ node --allow-natives-syntax bench/compression.mjs
## Compression algorithms

|name|ops/sec|samples|
|-|-|-|
|Deflate|9|11|
|Gzip|9|11|

I don't think that's giving a useful result. But I could be setting up the benchmark incorrectly.

@RafaelGSS
Copy link
Owner

Right, for this kind of operation, I believe a time-based benchmark would work better. Example: https://github.com/RafaelGSS/nodejs-bench-operations/blob/main/bench/array-append.mjs

@jsumners-nr
Copy link
Author

Thanks. I'll look into that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants