2020-11-09 02:21:04 +00:00
|
|
|
import std/monotimes, strformat, zip/zlib, zippy
|
2020-11-09 04:04:36 +00:00
|
|
|
# import miniz, nimPNG/nimz
|
2020-10-17 07:10:13 +00:00
|
|
|
|
2020-10-28 05:29:07 +00:00
|
|
|
const
|
2020-11-03 16:58:23 +00:00
|
|
|
zs = [
|
|
|
|
"alice29.txt.z",
|
|
|
|
"urls.10K.z",
|
2020-11-08 23:32:26 +00:00
|
|
|
"rfctest3.z",
|
2020-11-08 17:53:20 +00:00
|
|
|
"randtest3.z"
|
2020-11-03 16:58:23 +00:00
|
|
|
]
|
2020-11-01 22:16:36 +00:00
|
|
|
golds = [
|
2020-11-08 17:53:20 +00:00
|
|
|
"alice29.txt",
|
|
|
|
"urls.10K",
|
2020-11-08 23:32:26 +00:00
|
|
|
"rfctest3.gold",
|
|
|
|
"randtest3.gold"
|
2020-11-01 22:16:36 +00:00
|
|
|
]
|
2020-11-07 04:17:22 +00:00
|
|
|
iterations = 1000
|
2020-10-14 04:09:43 +00:00
|
|
|
|
2020-11-08 17:53:20 +00:00
|
|
|
block guzba_zippy_uncompress:
|
|
|
|
echo "https://github.com/guzba/zippy uncompress"
|
|
|
|
for z in zs:
|
|
|
|
let
|
|
|
|
compressed = readFile(&"tests/data/{z}")
|
|
|
|
start = getMonoTime().ticks
|
|
|
|
var c: int
|
|
|
|
for i in 0 ..< iterations:
|
|
|
|
let uncompressed = zippy.uncompress(compressed)
|
|
|
|
inc(c, uncompressed.len)
|
|
|
|
let delta = float64(getMonoTime().ticks - start) / 1000000000.0
|
|
|
|
echo &" {z}: {delta:.4f}s [{c}]"
|
2020-10-28 05:29:07 +00:00
|
|
|
|
2020-11-08 17:53:20 +00:00
|
|
|
block nimlang_zip_uncompress: # Requires zlib1.dll
|
|
|
|
echo "https://github.com/nim-lang/zip uncompress"
|
|
|
|
for z in zs:
|
2020-10-28 05:29:07 +00:00
|
|
|
let
|
2020-11-08 17:53:20 +00:00
|
|
|
compressed = readFile(&"tests/data/{z}")
|
2020-10-28 05:29:07 +00:00
|
|
|
start = getMonoTime().ticks
|
|
|
|
var c: int
|
|
|
|
for i in 0 ..< iterations:
|
2020-11-08 17:53:20 +00:00
|
|
|
let uncompressed = zlib.uncompress(compressed, stream = ZLIB_STREAM)
|
|
|
|
inc(c, uncompressed.len)
|
2020-10-28 05:29:07 +00:00
|
|
|
let delta = float64(getMonoTime().ticks - start) / 1000000000.0
|
2020-11-08 17:53:20 +00:00
|
|
|
echo &" {z}: {delta:.4f}s [{c}]"
|
2020-11-01 22:16:36 +00:00
|
|
|
|
|
|
|
# block treeform_miniz_uncompress:
|
|
|
|
# echo "https://github.com/treeform/miniz uncompress"
|
|
|
|
# for z in zs:
|
|
|
|
# let
|
|
|
|
# compressed = readFile(&"tests/data/{z}")
|
|
|
|
# start = getMonoTime().ticks
|
|
|
|
# var c: int
|
|
|
|
# for i in 0 ..< iterations:
|
|
|
|
# let uncompressed = miniz.uncompress(compressed)
|
|
|
|
# inc(c, uncompressed.len)
|
|
|
|
# let delta = float64(getMonoTime().ticks - start) / 1000000000.0
|
|
|
|
# echo &" {z}: {delta:.4f}s [{c}]"
|
2020-10-28 06:10:36 +00:00
|
|
|
|
2020-11-08 17:53:20 +00:00
|
|
|
# block jangko_nimPNG_uncompress:
|
|
|
|
# echo "https://github.com/jangko/nimPNG uncompress"
|
2020-11-01 22:16:36 +00:00
|
|
|
# for z in zs:
|
|
|
|
# let
|
|
|
|
# compressed = readFile(&"tests/data/{z}")
|
|
|
|
# start = getMonoTime().ticks
|
|
|
|
# var c: int
|
|
|
|
# for i in 0 ..< iterations:
|
2020-11-08 17:53:20 +00:00
|
|
|
# let uncompressed = zlib_decompress(nzInflateInit(compressed))
|
2020-11-01 22:16:36 +00:00
|
|
|
# inc(c, uncompressed.len)
|
|
|
|
# let delta = float64(getMonoTime().ticks - start) / 1000000000.0
|
|
|
|
# echo &" {z}: {delta:.4f}s [{c}]"
|
|
|
|
|
2020-11-08 17:53:20 +00:00
|
|
|
block guzba_zippy_compress:
|
|
|
|
echo "https://github.com/guzba/zippy compress"
|
|
|
|
for gold in golds:
|
|
|
|
let
|
|
|
|
uncompressed = readFile(&"tests/data/{gold}")
|
|
|
|
start = getMonoTime().ticks
|
|
|
|
var c: int
|
|
|
|
for i in 0 ..< iterations:
|
|
|
|
let compressed = zippy.compress(uncompressed, dfZlib)
|
|
|
|
inc(c, compressed.len)
|
|
|
|
let
|
|
|
|
delta = float64(getMonoTime().ticks - start) / 1000000000.0
|
2020-11-09 00:15:35 +00:00
|
|
|
reduction = 100 - (c / (uncompressed.len * iterations)) * 100
|
|
|
|
echo &" {gold}: {delta:.4f}s {(reduction):0.2f}%"
|
2020-11-08 17:53:20 +00:00
|
|
|
|
|
|
|
block nimlang_zip_compress: # Requires zlib1.dll
|
|
|
|
echo "https://github.com/nim-lang/zip compress"
|
|
|
|
for gold in golds:
|
|
|
|
let
|
|
|
|
uncompressed = readFile(&"tests/data/{gold}")
|
|
|
|
start = getMonoTime().ticks
|
|
|
|
var c: int
|
|
|
|
for i in 0 ..< iterations:
|
|
|
|
let compressed = zlib.compress(uncompressed, stream = ZLIB_STREAM)
|
|
|
|
inc(c, compressed.len)
|
|
|
|
let
|
|
|
|
delta = float64(getMonoTime().ticks - start) / 1000000000.0
|
2020-11-09 00:15:35 +00:00
|
|
|
reduction = 100 - (c / (uncompressed.len * iterations)) * 100
|
|
|
|
echo &" {gold}: {delta:.4f}s {(reduction):0.2f}%"
|
2020-11-08 17:53:20 +00:00
|
|
|
|
|
|
|
# block treeform_miniz_compress:
|
|
|
|
# echo "https://github.com/treeform/miniz compress"
|
2020-11-07 06:35:04 +00:00
|
|
|
# for gold in golds:
|
|
|
|
# let
|
|
|
|
# uncompressed = readFile(&"tests/data/{gold}")
|
|
|
|
# start = getMonoTime().ticks
|
|
|
|
# var c: int
|
|
|
|
# for i in 0 ..< iterations:
|
2020-11-08 17:53:20 +00:00
|
|
|
# let compressed = miniz.compress(uncompressed, 1)
|
2020-11-07 06:35:04 +00:00
|
|
|
# inc(c, compressed.len)
|
2020-11-01 22:16:36 +00:00
|
|
|
# let
|
2020-11-08 17:53:20 +00:00
|
|
|
# delta = float64(getMonoTime().ticks - start) / 1000000000.0
|
2020-11-09 00:15:35 +00:00
|
|
|
# reduction = 100 - (c / (uncompressed.len * iterations)) * 100
|
|
|
|
# echo &" {gold}: {delta:.4f}s {(reduction):0.2f}%"
|
2020-10-28 18:31:23 +00:00
|
|
|
|
2020-11-02 20:08:12 +00:00
|
|
|
# block jangko_nimPNG_compress:
|
|
|
|
# echo "https://github.com/jangko/nimPNG compress"
|
|
|
|
# for gold in golds:
|
|
|
|
# let
|
|
|
|
# uncompressed = readFile(&"tests/data/{gold}")
|
|
|
|
# start = getMonoTime().ticks
|
|
|
|
# var c: int
|
|
|
|
# for i in 0 ..< iterations:
|
|
|
|
# let compressed = zlib_compress(nzDeflateInit(uncompressed))
|
|
|
|
# inc(c, compressed.len)
|
2020-11-08 17:53:20 +00:00
|
|
|
# let
|
|
|
|
# delta = float64(getMonoTime().ticks - start) / 1000000000.0
|
2020-11-09 00:15:35 +00:00
|
|
|
# reduction = 100 - (c / (uncompressed.len * iterations)) * 100
|
|
|
|
# echo &" {gold}: {delta:.4f}s {reduction:0.2f}%"
|