Skip to content

Commit 3e3a16d

Browse files
committed
Added the extended benchmark (exbench.lua) that currently has MD5 and SHA256 checksum tests.
This script benchmarks MD5 and SHA256 checksum computation for files. It allows each benchmark to be skipped if an error occurs, otherwise it runs multiple iterations of the file checksum (using the entry file as a sample) to measure performance. `exbench.lua` is called by `bench.lua` to keep basic benchmarks separated from more complex and dependency-driven ones.
1 parent f14b508 commit 3e3a16d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

demo/extra/exbench.lua

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
local function benchmark_md5sum()
2+
local it, s = 5, pcall(require, "md5sum")
3+
local bm = BenchmarkStart("Checksum MD5", it)
4+
local file = io.open(arg[0], "rb")
5+
6+
if not s or not file then
7+
if file then file:close() end
8+
print(string.format("%17s", "Skipped"))
9+
return
10+
end
11+
12+
for _ = 1, it do
13+
md5_file(file)
14+
file:seek("set", 0)
15+
end
16+
file:close()
17+
BenchmarkEnd(bm)
18+
end
19+
20+
local function benchmark_sha256()
21+
local it, s = 5, pcall(require, "s256sum")
22+
local bm = BenchmarkStart("Checksum SHA256", it)
23+
local file = io.open(arg[0], "rb")
24+
25+
if not s or not file then
26+
if file then file:close() end
27+
print(string.format("%17s", "Skipped"))
28+
return
29+
end
30+
31+
for _ = 1, it do
32+
sha256_file(file)
33+
file:seek("set", 0)
34+
end
35+
file:close()
36+
BenchmarkEnd(bm)
37+
end
38+
39+
LIB = true
40+
benchmark_md5sum()
41+
benchmark_sha256()

0 commit comments

Comments
 (0)