Skip to content

Commit

Permalink
fix table in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Feb 7, 2024
1 parent 4a23294 commit 7703046
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 49 deletions.
136 changes: 99 additions & 37 deletions bench.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'json'

levels = [0] + (4..9).to_a
$levels = [0] + (4..9).to_a

def bench
def deflate_bench
`zig build bench -Doptimize=ReleaseSafe`
levels.each do |level|
$levels.each do |level|
`hyperfine --warmup 1 -r 3 'zig-out/bin/deflate_bench -l #{level}' 'zig-out/bin/deflate_bench -s -l #{level}' --export-json tmp/bench_#{level}.json`
`zig-out/bin/deflate_bench -l #{level} 2>tmp/size_#{level}`
`zig-out/bin/deflate_bench -s -l #{level} 2>tmp/size_std_#{level}`
Expand All @@ -15,49 +15,111 @@ def size_from_file(fn)
File.read(fn).split(" ")[1].to_i
end

data = []
def print_deflate_bench
data = []

levels.each do |level|
j = JSON.parse(File.read("tmp/bench_#{level}.json"))
$levels.each do |level|
j = JSON.parse(File.read("tmp/bench_#{level}.json"))

r = j["results"]
lib = 0
std = 1
if r[0]["command"].include?(" -s ")
lib = 1
std = 0
r = j["results"]
lib = 0
std = 1
if r[0]["command"].include?(" -s ")
lib = 1
std = 0
end

data << {
:level => level,
:std => {
:mean => r[std]["mean"].to_f * 1000,
:size => size_from_file("tmp/size_std_#{level}"),
},
:lib => {
:mean => r[lib]["mean"].to_f * 1000,
:size => size_from_file("tmp/size_#{level}"),
},
}
end

data << {
:level => level,
:std => {
:mean => r[std]["mean"].to_f * 1000,
:size => size_from_file("tmp/size_std_#{level}"),
},
:lib => {
:mean => r[lib]["mean"].to_f * 1000,
:size => size_from_file("tmp/size_#{level}"),
},
}
# pp data

print "| level | time [ms] | std [ms] | time/std |\n"
print "| :--- | ---: | ---: | ---: |\n"
data.each do |d|
std = d[:std][:mean]
lib = d[:lib][:mean]
print "|#{d[:level]} | #{'%.2f' % lib} | #{'%.2f' % std} | #{(std/lib).round( 2)} |\n"
end
print "\n"

print "| level | size | std size | diff | size/std |\n"
print "| :--- | ---: | ---: | ---: | ---: |\n"
data.each do |d|
std = d[:std][:size]
lib = d[:lib][:size]
print "| #{d[:level]} | #{lib} | #{std} | #{(std-lib)} | #{'%.4f' % (std.to_f/lib.to_f)} | \n"
end
print "\n"
end


pp data
def deflate_bench
data = []

`zig build bench -Doptimize=ReleaseSafe`
(0..3).to_a.each do |input|
`hyperfine --warmup 1 -r 3 'zig-out/bin/inflate_bench -i #{input}' 'zig-out/bin/inflate_bench -s -i #{input}' --export-json tmp/inflate_#{input}.json`

print "| level | time [ms] | std [ms] | time/std |\n"
print "| :--- | ---: | ---: | ---: |\n"
data.each do |d|
std = d[:std][:mean]
lib = d[:lib][:mean]
print "|#{d[:level]} | #{'%.2f' % lib} | #{'%.2f' % std} | #{(std/lib).round( 2)} |\n"
j = JSON.parse(File.read("tmp/inflate_#{input}.json"))
r = j["results"]
lib = 0
std = 1
if r[0]["command"].include?(" -s ")
lib = 1
std = 0
end
data << {
:input => input,
:std => {
:mean => r[std]["mean"].to_f * 1000,
},
:lib => {
:mean => r[lib]["mean"].to_f * 1000,
},
}
end

print "| file | size | time [ms] | std [ms] | time/std |\n"
print "| :--- | ---: | ---: | ---: | ---: |\n"
data.each do |d|
std = d[:std][:mean]
lib = d[:lib][:mean]
f = $inputs[d[:input]]
print "| #{f[:name]} | #{f[:bytes]} | #{'%.2f' % lib} | #{'%.2f' % std} | #{(std/lib).round( 2)} |\n"
end
print "\n"
end

$inputs = ["ziglang.tar.gz", "war_and_peace.txt.gz"]

print "| level | size | std [ms] | sizs/std |\n"
print "| :--- | ---: | ---: | ---: |\n"
data.each do |d|
std = d[:std][:size]
lib = d[:lib][:size]
print "| #{d[:level]} | #{lib} #{std} | #{(std-lib)} | #{'%.4f' % (std.to_f/lib.to_f)} | \n"
end
$inputs = [
{
:name => "ziglang.tar.gz",
:bytes => 177244160,
},
{
:name => "war_and_peace.txt.gz",
:bytes => 3359630,
},
{
:name => "large.tar.gz",
:bytes => 11162624,
},
{
:name => "cantrbry.tar.gz",
:bytes => 2821120,
},
];

deflate_bench
34 changes: 22 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ bytes: 24370812
[Go compression levels](https://github.com/ziglang/zig/blob/993a83081a975464d1201597cf6f4cb7f6735284/lib/std/compress/deflate/compressor.zig#L78)


Timing compression's with std lib implementation




| level | time [ms] | std [ms] | time/std |
| :--- | ---: | ---: | ---: |
| :--- | ---: | ---: | ---: |
|0 | 472.83 | 543.02 | 1.15 |
|4 | 1019.52 | 1222.02 | 1.2 |
|5 | 1401.85 | 1673.52 | 1.19 |
Expand All @@ -180,15 +183,22 @@ Timing compression's with std lib implementation
|8 | 4491.72 | 5118.71 | 1.14 |
|9 | 6713.99 | 8243.63 | 1.23 |

| level | size | std size | diff | size/std |
| :--- | ---: | ---: | ---: | ---: |
| 0 | 108398793 | 108397986 | -807 | 1.0000 |
| 4 | 26610575 | 26557083 | -53492 | 0.9980 |
| 5 | 25231037 | 25212703 | -18334 | 0.9993 |
| 6 | 24716324 | 24716123 | -201 | 1.0000 |
| 7 | 24572126 | 24562137 | -9989 | 0.9996 |
| 8 | 24419542 | 24425085 | 5543 | 1.0002 |
| 9 | 24370948 | 24389533 | 18585 | 1.0008 |



Size compression's with std lib implementation
| level | size | std [ms] | sizs/std |
| :--- | ---: | ---: | ---: |
| 0 | 108398793 108397986 | -807 | 1.0000 |
| 4 | 26610575 26557083 | -53492 | 0.9980 |
| 5 | 25231037 25212703 | -18334 | 0.9993 |
| 6 | 24716324 24716123 | -201 | 1.0000 |
| 7 | 24572126 24562137 | -9989 | 0.9996 |
| 8 | 24419542 24425085 | 5543 | 1.0002 |
| 9 | 24370948 24389533 | 18585 | 1.0008 |

| file | size | time [ms] | std [ms] | time/std |
| :--- | ---: | ---: | ---: | ---: |
| ziglang.tar.gz | 177244160 | 353.34 | 519.44 | 1.47 |
| war_and_peace.txt.gz | 3359630 | 13.55 | 21.36 | 1.58 |
| large.tar.gz | 11162624 | 37.93 | 57.53 | 1.52 |
| cantrbry.tar.gz | 2821120 | 9.08 | 14.30 | 1.57 |

0 comments on commit 7703046

Please sign in to comment.