bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2022-04-14 14:22:41 +00:00
|
|
|
stew/byteutils,
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
os, strformat, stats, times,
|
2022-04-14 14:22:41 +00:00
|
|
|
snappy, cpp_snappy, ../snappy/[faststreams, streams]
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
currentDir = currentSourcePath.parentDir
|
|
|
|
dataDir = currentDir & DirSep & "data" & DirSep
|
|
|
|
|
|
|
|
type
|
|
|
|
TestTimes = object
|
2022-04-14 14:22:41 +00:00
|
|
|
inMemory: array[2, RunningStat]
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
fastStreams: array[2, RunningStat]
|
|
|
|
nimStreams: array[2, RunningStat]
|
|
|
|
cppLib: array[2, RunningStat]
|
|
|
|
size: int
|
|
|
|
|
|
|
|
template timeit(timerVar: var RunningStat, code: untyped) =
|
|
|
|
let t0 = cpuTime()
|
|
|
|
code
|
|
|
|
timerVar.push cpuTime() - t0
|
|
|
|
|
|
|
|
var printedHeader = false
|
|
|
|
|
|
|
|
proc printTimes(t: TestTimes, name: string) =
|
|
|
|
func f(t: array[2, RunningStat]): string =
|
|
|
|
&"{t[0].mean * 1000 :>7.3f} /{t[1].mean * 1000 :>7.3f}, "
|
|
|
|
|
|
|
|
if not printedHeader:
|
|
|
|
printedHeader = true
|
2022-04-14 14:22:41 +00:00
|
|
|
echo &"{\"inMemory\" :>16}, {\"fastStreams\" :>16}, {\"nimStreams\" :>16}, " &
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
&"{\"cppLib\" :>16}, {\"Samples\" :>12}, {\"Size\" :>12}, {\"Test\" :>12}"
|
|
|
|
|
2022-04-14 14:22:41 +00:00
|
|
|
echo f(t.inMemory),
|
|
|
|
f(t.fastStreams),
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
f(t.nimStreams),
|
|
|
|
f(t.cppLib),
|
|
|
|
&"{t.fastStreams[0].n :>12}, ",
|
|
|
|
&"{t.size :>12}, ",
|
|
|
|
name
|
|
|
|
|
|
|
|
proc readSource(sourceName: string): seq[byte] =
|
|
|
|
var f = open(sourceName, fmRead)
|
|
|
|
if f.isNil: return
|
|
|
|
let size = f.getFileSize()
|
2022-04-14 14:22:41 +00:00
|
|
|
result = newSeqUninitialized[byte](size)
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
doAssert(size == f.readBytes(result, 0, size))
|
|
|
|
f.close()
|
|
|
|
|
allow skipping crc32 integrity check (#22)
Some data is already protected by stronger checks - crc32 on the other
hand significantly slows down framed reading - ie 2.5x slower:
```
118.853 / 41.781, 129.115 / 0.000, 188.438 / 0.000, 90.565 / 44.371, 50, 115613038, state-6800000-488b7150-d613b584.ssz
186.600 / 97.202, 191.935 /123.325, 0.000 / 0.000, 0.000 / 0.000, 50, 115613038, state-6800000-488b7150-d613b584.ssz(framed)
```
The difference between unframed and framed decoding is the CRC32 check -
it takes ~50ms on a decent laptop for a 110mb file.
2023-07-25 15:50:36 +00:00
|
|
|
proc memEncode(input: openArray[byte]): seq[byte] {.noinline.} =
|
|
|
|
snappy.encode(input)
|
|
|
|
|
|
|
|
proc memDecode(input: openArray[byte]): seq[byte] {.noinline.} =
|
|
|
|
snappy.decode(input)
|
|
|
|
|
|
|
|
proc streamsEncode(input: openArray[byte]): seq[byte] {.noinline.} =
|
2022-04-14 14:22:41 +00:00
|
|
|
let
|
|
|
|
ins = newStringStream(string.fromBytes(input))
|
|
|
|
outs = newStringStream()
|
|
|
|
compress(ins, input.len, outs)
|
|
|
|
outs.setPosition(0)
|
|
|
|
outs.readAll().toBytes() # This line is a hotspot due to missing RVO
|
|
|
|
|
allow skipping crc32 integrity check (#22)
Some data is already protected by stronger checks - crc32 on the other
hand significantly slows down framed reading - ie 2.5x slower:
```
118.853 / 41.781, 129.115 / 0.000, 188.438 / 0.000, 90.565 / 44.371, 50, 115613038, state-6800000-488b7150-d613b584.ssz
186.600 / 97.202, 191.935 /123.325, 0.000 / 0.000, 0.000 / 0.000, 50, 115613038, state-6800000-488b7150-d613b584.ssz(framed)
```
The difference between unframed and framed decoding is the CRC32 check -
it takes ~50ms on a decent laptop for a 110mb file.
2023-07-25 15:50:36 +00:00
|
|
|
proc faststreamsEncode(input: openArray[byte]): seq[byte] {.noinline.} =
|
2022-04-14 14:22:41 +00:00
|
|
|
let
|
|
|
|
ins = unsafeMemoryInput(input)
|
|
|
|
outs = memoryOutput()
|
|
|
|
compress(ins, outs)
|
|
|
|
outs.getOutput() # This line is a hotspot due to missing RVO
|
|
|
|
|
allow skipping crc32 integrity check (#22)
Some data is already protected by stronger checks - crc32 on the other
hand significantly slows down framed reading - ie 2.5x slower:
```
118.853 / 41.781, 129.115 / 0.000, 188.438 / 0.000, 90.565 / 44.371, 50, 115613038, state-6800000-488b7150-d613b584.ssz
186.600 / 97.202, 191.935 /123.325, 0.000 / 0.000, 0.000 / 0.000, 50, 115613038, state-6800000-488b7150-d613b584.ssz(framed)
```
The difference between unframed and framed decoding is the CRC32 check -
it takes ~50ms on a decent laptop for a 110mb file.
2023-07-25 15:50:36 +00:00
|
|
|
proc memEncodeFramed(input: openArray[byte]): seq[byte] {.noinline.} =
|
|
|
|
snappy.encodeFramed(input)
|
|
|
|
|
|
|
|
proc memDecodeFramed(input: openArray[byte]): seq[byte] {.noinline.} =
|
|
|
|
snappy.decodeFramed(input)
|
|
|
|
|
|
|
|
proc faststreamsEncodeFramed(input: openArray[byte]): seq[byte] {.noinline.} =
|
2022-04-14 14:22:41 +00:00
|
|
|
let
|
|
|
|
ins = unsafeMemoryInput(input)
|
|
|
|
outs = memoryOutput()
|
|
|
|
compressFramed(ins, outs)
|
|
|
|
outs.getOutput() # This line is a hotspot due to missing RVO
|
|
|
|
|
allow skipping crc32 integrity check (#22)
Some data is already protected by stronger checks - crc32 on the other
hand significantly slows down framed reading - ie 2.5x slower:
```
118.853 / 41.781, 129.115 / 0.000, 188.438 / 0.000, 90.565 / 44.371, 50, 115613038, state-6800000-488b7150-d613b584.ssz
186.600 / 97.202, 191.935 /123.325, 0.000 / 0.000, 0.000 / 0.000, 50, 115613038, state-6800000-488b7150-d613b584.ssz(framed)
```
The difference between unframed and framed decoding is the CRC32 check -
it takes ~50ms on a decent laptop for a 110mb file.
2023-07-25 15:50:36 +00:00
|
|
|
proc faststreamsDecodeFramed(input: openArray[byte]): seq[byte] {.noinline.} =
|
2022-04-14 14:22:41 +00:00
|
|
|
let
|
|
|
|
ins = unsafeMemoryInput(input)
|
|
|
|
outs = memoryOutput()
|
|
|
|
uncompressFramed(ins, outs)
|
|
|
|
outs.getOutput() # This line is a hotspot due to missing RVO
|
|
|
|
|
|
|
|
proc timedRoundTrip(msg: string, source: openArray[byte], iterations = 100) =
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
when declared(GC_fullCollect):
|
|
|
|
GC_fullCollect()
|
|
|
|
|
|
|
|
var timers: TestTimes
|
|
|
|
timers.size = source.len()
|
|
|
|
|
|
|
|
for i in 0..<iterations:
|
2022-04-14 14:22:41 +00:00
|
|
|
timeit(timers.inMemory[0]):
|
allow skipping crc32 integrity check (#22)
Some data is already protected by stronger checks - crc32 on the other
hand significantly slows down framed reading - ie 2.5x slower:
```
118.853 / 41.781, 129.115 / 0.000, 188.438 / 0.000, 90.565 / 44.371, 50, 115613038, state-6800000-488b7150-d613b584.ssz
186.600 / 97.202, 191.935 /123.325, 0.000 / 0.000, 0.000 / 0.000, 50, 115613038, state-6800000-488b7150-d613b584.ssz(framed)
```
The difference between unframed and framed decoding is the CRC32 check -
it takes ~50ms on a decent laptop for a 110mb file.
2023-07-25 15:50:36 +00:00
|
|
|
let encodedWithSnappy = memEncode(source)
|
2022-04-14 14:22:41 +00:00
|
|
|
timeit(timers.inMemory[1]):
|
allow skipping crc32 integrity check (#22)
Some data is already protected by stronger checks - crc32 on the other
hand significantly slows down framed reading - ie 2.5x slower:
```
118.853 / 41.781, 129.115 / 0.000, 188.438 / 0.000, 90.565 / 44.371, 50, 115613038, state-6800000-488b7150-d613b584.ssz
186.600 / 97.202, 191.935 /123.325, 0.000 / 0.000, 0.000 / 0.000, 50, 115613038, state-6800000-488b7150-d613b584.ssz(framed)
```
The difference between unframed and framed decoding is the CRC32 check -
it takes ~50ms on a decent laptop for a 110mb file.
2023-07-25 15:50:36 +00:00
|
|
|
let decodedWithSnappy = memDecode(encodedWithSnappy)
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
|
2022-04-14 14:22:41 +00:00
|
|
|
timeit(timers.fastStreams[0]):
|
|
|
|
let encodedWithFastStreams = faststreamsEncode(source)
|
|
|
|
# timeit(timers.fastStreams[1]):
|
|
|
|
# var decodedWithFastStreams = snappy.decode(encodedWithFastStreams)
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
|
|
|
|
timeit(timers.nimStreams[0]):
|
2022-04-14 14:22:41 +00:00
|
|
|
var encodedWithNimStreams = streamsEncode(source)
|
|
|
|
# timeit(timers.nimStreams[1]):
|
|
|
|
# var decodedWithNimStreams = streamsDecode(encodedWithNimStreams)
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
|
|
|
|
timeit(timers.cppLib[0]):
|
|
|
|
var encodedWithCpp = cpp_snappy.encode(source)
|
|
|
|
timeit(timers.cppLib[1]):
|
|
|
|
var decodedWithCpp = cpp_snappy.decode(encodedWithCpp)
|
|
|
|
|
2022-04-14 14:22:41 +00:00
|
|
|
# doAssert decodedWithFastStreams == source
|
|
|
|
# doAssert decodedWithNimStreams == source
|
|
|
|
doAssert decodedWithSnappy == source
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
doAssert decodedWithCpp == source
|
|
|
|
|
|
|
|
printTimes(timers, msg)
|
|
|
|
|
2022-04-14 14:22:41 +00:00
|
|
|
proc timedRoundTripFramed(msg: string, source: openArray[byte], iterations = 100) =
|
|
|
|
when declared(GC_fullCollect):
|
|
|
|
GC_fullCollect()
|
|
|
|
|
|
|
|
var timers: TestTimes
|
|
|
|
timers.size = source.len()
|
|
|
|
|
|
|
|
for i in 0..<iterations:
|
|
|
|
timeit(timers.inMemory[0]):
|
allow skipping crc32 integrity check (#22)
Some data is already protected by stronger checks - crc32 on the other
hand significantly slows down framed reading - ie 2.5x slower:
```
118.853 / 41.781, 129.115 / 0.000, 188.438 / 0.000, 90.565 / 44.371, 50, 115613038, state-6800000-488b7150-d613b584.ssz
186.600 / 97.202, 191.935 /123.325, 0.000 / 0.000, 0.000 / 0.000, 50, 115613038, state-6800000-488b7150-d613b584.ssz(framed)
```
The difference between unframed and framed decoding is the CRC32 check -
it takes ~50ms on a decent laptop for a 110mb file.
2023-07-25 15:50:36 +00:00
|
|
|
let encodedWithSnappy = memEncodeFramed(source)
|
2022-04-14 14:22:41 +00:00
|
|
|
timeit(timers.inMemory[1]):
|
allow skipping crc32 integrity check (#22)
Some data is already protected by stronger checks - crc32 on the other
hand significantly slows down framed reading - ie 2.5x slower:
```
118.853 / 41.781, 129.115 / 0.000, 188.438 / 0.000, 90.565 / 44.371, 50, 115613038, state-6800000-488b7150-d613b584.ssz
186.600 / 97.202, 191.935 /123.325, 0.000 / 0.000, 0.000 / 0.000, 50, 115613038, state-6800000-488b7150-d613b584.ssz(framed)
```
The difference between unframed and framed decoding is the CRC32 check -
it takes ~50ms on a decent laptop for a 110mb file.
2023-07-25 15:50:36 +00:00
|
|
|
let decodedWithSnappy = memDecodeFramed(encodedWithSnappy)
|
2022-04-14 14:22:41 +00:00
|
|
|
|
|
|
|
timeit(timers.fastStreams[0]):
|
|
|
|
let encodedWithFastStreams = faststreamsEncodeFramed(source)
|
|
|
|
timeit(timers.fastStreams[1]):
|
|
|
|
var decodedWithFastStreams = faststreamsDecodeFramed(encodedWithFastStreams)
|
|
|
|
|
|
|
|
# timeit(timers.nimStreams[0]):
|
|
|
|
# var encodedWithNimStreams = streamsEncode(source)
|
|
|
|
# timeit(timers.nimStreams[1]):
|
|
|
|
# var decodedWithNimStreams = streamsDecode(encodedWithNimStreams)
|
|
|
|
|
|
|
|
doAssert decodedWithFastStreams == source
|
|
|
|
# doAssert decodedWithNimStreams == source
|
|
|
|
doAssert decodedWithSnappy == source
|
|
|
|
|
|
|
|
printTimes(timers, msg & "(framed)")
|
|
|
|
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
proc roundTrip(msg: string, source: openArray[byte], iterations = 100) =
|
|
|
|
timedRoundTrip(msg, source, iterations)
|
2022-04-14 14:22:41 +00:00
|
|
|
timedRoundTripFramed(msg, source, iterations)
|
bump cppsnappy, split out benchmark
* benchmark both compression and decompression
* bump C++-snappy: it's gotten better over the years
```
fastStreams, openArrays, nimStreams, cppLib, Samples, Size, Test
0.281 / 0.139, 0.295 / 0.220, 0.528 / 0.238, 0.140 / 0.047, 100, 102400, html
2.697 / 1.457, 3.263 / 1.993, 6.106 / 2.026, 1.655 / 0.530, 100, 702087, urls.10K
0.021 / 0.011, 0.017 / 0.011, 0.031 / 0.011, 0.014 / 0.009, 100, 123093, fireworks.jpeg
0.057 / 0.019, 0.051 / 0.036, 0.092 / 0.042, 0.021 / 0.011, 100, 102400, paper-100k.pdf
1.153 / 0.565, 1.210 / 0.904, 2.172 / 0.985, 0.575 / 0.184, 100, 409600, html_x_4
0.887 / 0.582, 0.976 / 0.743, 1.923 / 0.712, 0.536 / 0.202, 100, 152089, alice29.txt
0.771 / 0.504, 0.850 / 0.639, 1.678 / 0.606, 0.482 / 0.184, 100, 129301, asyoulik.txt
2.349 / 1.518, 2.553 / 1.946, 5.057 / 1.913, 1.391 / 0.522, 100, 426754, lcet10.txt
2.983 / 1.951, 3.241 / 2.408, 6.680 / 2.342, 1.882 / 0.735, 100, 481861, plrabn12.txt
0.293 / 0.120, 0.306 / 0.210, 0.542 / 0.241, 0.131 / 0.042, 100, 118588, geo.protodata
0.743 / 0.501, 0.738 / 0.620, 1.597 / 0.640, 0.414 / 0.191, 100, 184320, kppkn.gtb
0.087 / 0.054, 0.102 / 0.067, 0.193 / 0.061, 0.052 / 0.022, 100, 14564, Mark.Twain-Tom.Sawyer.txt
66.886 / 20.880, 105.393 / 37.907, 210.197 / 38.867, 34.273 / 10.193, 10, 38942424, state-2560000-114a593d-0d5e08e8.ssz
```
In general, we're consistently about 2x slower than C++ right now.
2021-12-30 12:33:27 +00:00
|
|
|
|
|
|
|
proc roundTrip(sourceName: string, iterations = 100) =
|
|
|
|
var src = readSource(sourceName)
|
|
|
|
roundTrip(extractFilename(sourceName), src, iterations)
|
|
|
|
|
|
|
|
roundTrip(dataDir & "html")
|
|
|
|
roundTrip(dataDir & "urls.10K")
|
|
|
|
roundTrip(dataDir & "fireworks.jpeg")
|
|
|
|
roundTrip(dataDir & "paper-100k.pdf")
|
|
|
|
roundTrip(dataDir & "html_x_4")
|
|
|
|
roundTrip(dataDir & "alice29.txt")
|
|
|
|
roundTrip(dataDir & "asyoulik.txt")
|
|
|
|
roundTrip(dataDir & "lcet10.txt")
|
|
|
|
roundTrip(dataDir & "plrabn12.txt")
|
|
|
|
roundTrip(dataDir & "geo.protodata")
|
|
|
|
roundTrip(dataDir & "kppkn.gtb")
|
|
|
|
roundTrip(dataDir & "Mark.Twain-Tom.Sawyer.txt")
|
|
|
|
|
allow skipping crc32 integrity check (#22)
Some data is already protected by stronger checks - crc32 on the other
hand significantly slows down framed reading - ie 2.5x slower:
```
118.853 / 41.781, 129.115 / 0.000, 188.438 / 0.000, 90.565 / 44.371, 50, 115613038, state-6800000-488b7150-d613b584.ssz
186.600 / 97.202, 191.935 /123.325, 0.000 / 0.000, 0.000 / 0.000, 50, 115613038, state-6800000-488b7150-d613b584.ssz(framed)
```
The difference between unframed and framed decoding is the CRC32 check -
it takes ~50ms on a decent laptop for a 110mb file.
2023-07-25 15:50:36 +00:00
|
|
|
# ncli_db --db:db rewindState 0x488b7150f092949f1dfc3137c4e2909a20fe9739d67a5185d75dbd0440c51edd 6800000
|
|
|
|
if fileExists(dataDir & "state-6800000-488b7150-d613b584.ssz"):
|
|
|
|
roundTrip(dataDir & "state-6800000-488b7150-d613b584.ssz", 50)
|