Skip to content

Commit

Permalink
add benchmarks (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 authored Sep 15, 2024
1 parent cef9aaa commit e7edfed
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -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)
```
32 changes: 32 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e7edfed

Please sign in to comment.