From e7edfede45ed5c7a94000f6e2346576a1fcfa4e1 Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Sun, 15 Sep 2024 12:52:18 -0400 Subject: [PATCH] add benchmarks (#69) --- .gitignore | 6 +++--- benchmark/Project.toml | 6 ++++++ benchmark/README.md | 11 +++++++++++ benchmark/benchmarks.jl | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 benchmark/Project.toml create mode 100644 benchmark/README.md create mode 100644 benchmark/benchmarks.jl diff --git a/.gitignore b/.gitignore index 1ca91c8..64fe833 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,13 @@ *.jl.*.cov *.jl.mem /Manifest.toml -/deps/build.log -/deps/deps.jl -/deps/usr/ src/libzstd/LibTemplate.jl src/libzstd/ctypes.jl /github/ settings.json +**/*.json +**/*.json.tmp +benchmark/Manifest.toml dictionary github_users_sample_set.tar github_users_sample_set.tar.zst diff --git a/benchmark/Project.toml b/benchmark/Project.toml new file mode 100644 index 0000000..397c896 --- /dev/null +++ b/benchmark/Project.toml @@ -0,0 +1,6 @@ +[deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +CodecZstd = "6b39b394-51ab-5f42-8807-6242bab2b4c2" +PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 0000000..74d2002 --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,11 @@ +# CodecZstd.jl benchmarks + +This directory contains benchmarks for CodecZstd. To run all the +benchmarks, launch `julia --project=benchmark` and enter: + +``` julia +using PkgBenchmark +import CodecZstd + +benchmarkpkg(CodecZstd) +``` \ No newline at end of file diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..a60930e --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,32 @@ +using BenchmarkTools +using Random +using TranscodingStreams +using CodecZstd + +const SUITE = BenchmarkGroup() +cbench = SUITE["compression"] = BenchmarkGroup() +dbench = SUITE["decompression"] = BenchmarkGroup() + +ccodec = ZstdCompressor() +dcodec = ZstdDecompressor() +TranscodingStreams.initialize(ccodec) +TranscodingStreams.initialize(dcodec) + +for N in [100, 100000, 1000000] + u1 = rand(Xoshiro(1234), UInt8, N) + c1 = transcode(ZstdCompressor, u1) + cbench["uncompressible"][N] = @benchmarkable transcode($ccodec, $u1) + dbench["uncompressible"][N] = @benchmarkable transcode($dcodec, $c1) + + u2 = rand(Xoshiro(1234), 0x00:0x01, N) + c2 = transcode(ZstdCompressor, u2) + cbench["compressible-bytes"][N] = @benchmarkable transcode($ccodec, $u2) + dbench["compressible-bytes"][N] = @benchmarkable transcode($dcodec, $c2) + + f = round.(randn(Xoshiro(1234), N); base=2, digits=7) + # byte shuffle + u3 = vec(permutedims(reinterpret(reshape, UInt8, f),(2,1))) + c3 = transcode(ZstdCompressor, u3) + cbench["byteshuffle"][N] = @benchmarkable transcode($ccodec, $u3) + dbench["byteshuffle"][N] = @benchmarkable transcode($dcodec, $c3) +end \ No newline at end of file