summaryrefslogtreecommitdiff
path: root/tests/benchmarks/hash.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-30 00:50:15 +0800
committerruki <[email protected]>2025-09-30 00:50:15 +0800
commitaced9c7ece3127676e9cb25d2161ff08e5560149 (patch)
treef09e90f1dfb0913a6cf830f059bb37f2c63ac7f7 /tests/benchmarks/hash.lua
parent21b740673ab4b53d7baea2c890ddad31e32524a5 (diff)
add hash benchmarks
Diffstat (limited to 'tests/benchmarks/hash.lua')
-rw-r--r--tests/benchmarks/hash.lua82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/benchmarks/hash.lua b/tests/benchmarks/hash.lua
new file mode 100644
index 000000000..ae8a29d21
--- /dev/null
+++ b/tests/benchmarks/hash.lua
@@ -0,0 +1,82 @@
+local COUNT = 1000000
+
+function test_md5(data)
+ local h
+ local t = os.mclock()
+ for i = 1, COUNT do
+ h = hash.md5(data)
+ end
+ t = os.mclock() - t
+ print("md5(%d): %d ms, hash: %s", COUNT, t, h)
+end
+
+function test_sha1(data)
+ local h
+ local t = os.mclock()
+ for i = 1, COUNT do
+ h = hash.sha1(data)
+ end
+ t = os.mclock() - t
+ print("sha1(%d): %d ms, hash: %s", COUNT, t, h)
+end
+
+function test_sha256(data)
+ local h
+ local t = os.mclock()
+ for i = 1, COUNT do
+ h = hash.sha256(data)
+ end
+ t = os.mclock() - t
+ print("sha256(%d): %d ms, hash: %s", COUNT, t, h)
+end
+
+function test_uuid(data)
+ local h
+ local t = os.mclock()
+ for i = 1, COUNT do
+ h = hash.uuid(data)
+ end
+ t = os.mclock() - t
+ print("uuid(%d): %d ms, hash: %s", COUNT, t, h)
+end
+
+function test_uuid4(data)
+ local h
+ local t = os.mclock()
+ for i = 1, COUNT do
+ h = hash.uuid4(data)
+ end
+ t = os.mclock() - t
+ print("uuid4(%d): %d ms, hash: %s", COUNT, t, h)
+end
+
+function test_strhash32(data)
+ local h
+ local t = os.mclock()
+ for i = 1, COUNT do
+ h = hash.strhash32(data)
+ end
+ t = os.mclock() - t
+ print("strhash32(%d): %d ms, hash: %s", COUNT, t, h)
+end
+
+function test_strhash128(data)
+ local h
+ local t = os.mclock()
+ for i = 1, COUNT do
+ h = hash.strhash128(data)
+ end
+ t = os.mclock() - t
+ print("strhash128(%d): %d ms, hash: %s", COUNT, t, h)
+end
+
+function main()
+ local data = io.readfile(os.programfile())
+ --test_md5(data)
+ --test_sha1(data)
+ --test_sha256(data)
+ test_uuid(data)
+ test_uuid4(data)
+ test_strhash32(data)
+ test_strhash128(data)
+end