diff --git a/.gitignore b/.gitignore index abbce2e..64431eb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /.vscode/ /test/Manifest.toml +/benchmark/Manifest.toml /Manifest.toml fixture.tar.gz fixture diff --git a/benchmark/Project.toml b/benchmark/Project.toml new file mode 100644 index 0000000..fb4c5a1 --- /dev/null +++ b/benchmark/Project.toml @@ -0,0 +1,6 @@ +[deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +ZipArchives = "49080126-0e18-4c2a-b176-c102e4b3760c" diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 0000000..9e490b1 --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,11 @@ +# ZipArchives.jl benchmarks + +This directory contains benchmarks for ZipArchives. To run all the +benchmarks, launch `julia --project=benchmark` and enter: + +``` julia +using PkgBenchmark +import ZipArchives + +benchmarkpkg(ZipArchives) +``` \ No newline at end of file diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..15fecf2 --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,24 @@ +using BenchmarkTools +using Random +using ZipArchives + +const SUITE = BenchmarkGroup() +rbench = SUITE["reading"] = BenchmarkGroup() + +sink = IOBuffer() +names = String[] +ZipWriter(sink) do w + for i in 1:2000 + local name = String(rand(UInt8('a'):UInt8('z'), 100)) + push!(names, name) + zip_writefile(w, name, rand(UInt8, 10000)) + end +end +data = take!(sink) +r = ZipReader(data) + +rbench["ZipReader"] = @benchmarkable ZipReader($(data)) +rbench["zip_findlast_entry nothing"] = @benchmarkable zip_findlast_entry($(r), $("abc")) +rbench["zip_findlast_entry first"] = @benchmarkable zip_findlast_entry($(r), $(names[begin])) +rbench["zip_findlast_entry last"] = @benchmarkable zip_findlast_entry($(r), $(names[end])) +rbench["zip_readentry"] = @benchmarkable zip_readentry($(r), $(1000)) diff --git a/src/reader.jl b/src/reader.jl index 25ec83f..b220aa2 100644 --- a/src/reader.jl +++ b/src/reader.jl @@ -202,8 +202,9 @@ Return the index of the last entry with name `s` or `nothing` if not found. zip_findlast_entry(x::HasEntries, s::AbstractString)::Union{Nothing, Int} = zip_findlast_entry(x, String(s)) function zip_findlast_entry(x::HasEntries, s::String)::Union{Nothing, Int} data = codeunits(s) - findlast(eachindex(x.entries)) do i - _name_view(x, i) == data + n = length(data) + findlast(x.entries) do e + n == length(e.name_range) && view(x.central_dir_buffer, e.name_range) == data end end