file = ARGV[0]
def calc(label, cmd, file)
t = Time.now
`#{cmd}`
t = Time.now - t
size = File.size(file)
puts "#{label}: #{sprintf("%.6f", t)} sec, #{size} bytes"
end
puts "original: #{File.size(file)} bytes"
(1..10).each {|level|
calc("brotli #{level}", "brotli --force --quality #{level} --input #{file} --output #{file}.br", "#{file}.br")
}
((1..9).to_a + [10,15,20,25,30]).each {|level|
calc("zopfli #{level}", "zopfli --i#{level} #{file}", "#{file}.gz")
}
(1..9).each {|level|
calc("gzip #{level}", "gzip -#{level} -c -f #{file} > #{file}.gz", "#{file}.gz")
}
ギリギリまで冗長性を削除しているHTMLをテストに利用してみたところ、gzip-18%、zopfli-16%となり素晴らしい結果でした。
$ ruby test.rb test.html
original: 15652 bytes
brotli 1: 0.002033 sec, 5047 bytes
brotli 2: 0.001699 sec, 5009 bytes
brotli 3: 0.001784 sec, 4980 bytes
brotli 4: 0.002044 sec, 4747 bytes
brotli 5: 0.002624 sec, 4172 bytes
brotli 6: 0.003607 sec, 4162 bytes
brotli 7: 0.004323 sec, 4107 bytes
brotli 8: 0.004056 sec, 4100 bytes
brotli 9: 0.005396 sec, 4087 bytes
brotli 10: 0.043826 sec, 3881 bytes
zopfli 1: 0.252186 sec, 4612 bytes
zopfli 2: 0.273344 sec, 4606 bytes
zopfli 3: 0.306744 sec, 4603 bytes
zopfli 4: 0.265884 sec, 4603 bytes
zopfli 5: 0.327768 sec, 4603 bytes
zopfli 6: 0.302046 sec, 4603 bytes
zopfli 7: 0.322396 sec, 4603 bytes
zopfli 8: 0.310021 sec, 4603 bytes
zopfli 9: 0.340069 sec, 4605 bytes
zopfli 10: 0.338060 sec, 4605 bytes
zopfli 15: 0.383038 sec, 4603 bytes
zopfli 20: 0.392550 sec, 4603 bytes
zopfli 25: 0.360510 sec, 4603 bytes
zopfli 30: 0.277653 sec, 4603 bytes
gzip 1: 0.002162 sec, 5122 bytes
gzip 2: 0.001989 sec, 5033 bytes
gzip 3: 0.001755 sec, 4981 bytes
gzip 4: 0.001775 sec, 4791 bytes
gzip 5: 0.001814 sec, 4739 bytes
gzip 6: 0.002046 sec, 4734 bytes
gzip 7: 0.002149 sec, 4732 bytes
gzip 8: 0.003049 sec, 4729 bytes
gzip 9: 0.002149 sec, 4729 bytes
前回利用したJSONファイルも確認してみた。これもギリギリまで冗長性は排除していますが、gzip-18%、zopfli-13%と素晴らしい結果でした。
$ ruby test.rb test.json
original: 438146 bytes
brotli 1: 0.008709 sec, 143812 bytes
brotli 2: 0.010706 sec, 142193 bytes
brotli 3: 0.012212 sec, 139530 bytes
brotli 4: 0.014156 sec, 138066 bytes
brotli 5: 0.026652 sec, 125302 bytes
brotli 6: 0.034410 sec, 123004 bytes
brotli 7: 0.043270 sec, 120508 bytes
brotli 8: 0.052716 sec, 119024 bytes
brotli 9: 0.070479 sec, 118026 bytes
brotli 10: 1.337605 sec, 104952 bytes
zopfli 1: 1.116614 sec, 120899 bytes
zopfli 2: 1.178194 sec, 120623 bytes
zopfli 3: 1.271736 sec, 120548 bytes
zopfli 4: 1.345818 sec, 120485 bytes
zopfli 5: 1.492534 sec, 120455 bytes
zopfli 6: 1.529910 sec, 120438 bytes
zopfli 7: 1.594525 sec, 120432 bytes
zopfli 8: 1.665754 sec, 120408 bytes
zopfli 9: 1.750016 sec, 120398 bytes
zopfli 10: 1.884538 sec, 120392 bytes
zopfli 15: 2.519045 sec, 120390 bytes
zopfli 20: 3.101787 sec, 120390 bytes
zopfli 25: 2.980007 sec, 120390 bytes
zopfli 30: 3.701557 sec, 120387 bytes
gzip 1: 0.013838 sec, 170265 bytes
gzip 2: 0.039754 sec, 161152 bytes
gzip 3: 0.034746 sec, 151130 bytes
gzip 4: 0.015178 sec, 144631 bytes
gzip 5: 0.019380 sec, 134481 bytes
gzip 6: 0.030051 sec, 130714 bytes
gzip 7: 0.040470 sec, 129113 bytes
gzip 8: 0.066297 sec, 127468 bytes
gzip 9: 0.066368 sec, 127468 bytes
brotliのqualityは、応答性を求めるなら4、ほどほどの圧縮時間で良ければ9、圧縮時間を問わなければ10を利用するのが良さそうです。
0 件のコメント:
コメントを投稿