summaryrefslogtreecommitdiff
path: root/tests/benchmarks/hash.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-30 22:35:21 +0800
committerruki <[email protected]>2025-09-30 22:35:21 +0800
commit9dd7fe46d8678216b62016b721fe084d5bad9246 (patch)
tree75550b8f9c84d9febd5921ce9598468173682454 /tests/benchmarks/hash.lua
parente225e4e8abf4a6fbf27343737a642c54f7c93643 (diff)
update hash test
Diffstat (limited to 'tests/benchmarks/hash.lua')
-rw-r--r--tests/benchmarks/hash.lua55
1 files changed, 36 insertions, 19 deletions
diff --git a/tests/benchmarks/hash.lua b/tests/benchmarks/hash.lua
index 119f1bb71..8c70c342a 100644
--- a/tests/benchmarks/hash.lua
+++ b/tests/benchmarks/hash.lua
@@ -40,22 +40,13 @@ end
function test_uuid(data)
local h
+ local n = COUNT / 10000
local t = os.mclock()
- for i = 1, COUNT do
+ for i = 1, n 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)
+ print("uuid(%d): %d ms, hash: %s", COUNT, t * 10000, h)
end
function test_xxhash64(data)
@@ -84,33 +75,59 @@ end
function test_strhash32(data)
local h
+ local n = COUNT / 10000
local t = os.mclock()
- for i = 1, COUNT do
+ for i = 1, n do
h = hash.strhash32(data)
end
t = os.mclock() - t
- print("strhash32(%d): %d ms, hash: %s", COUNT, t, h)
+ print("strhash32(%d): %d ms, hash: %s", COUNT, t * 10000, h)
end
function test_strhash128(data)
local h
+ local n = COUNT / 10000
local t = os.mclock()
- for i = 1, COUNT do
+ for i = 1, n do
h = hash.strhash128(data)
end
t = os.mclock() - t
- print("strhash128(%d): %d ms, hash: %s", COUNT, t, h)
+ print("strhash128(%d): %d ms, hash: %s", COUNT, t * 10000, h)
end
-function main()
- local data = io.readfile(os.programfile())
+function test_longstr()
+ print("========================================== test long string ==========================================")
+ local data = ""
+ for i = 1, 10000 do
+ data = data .. "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ end
test_md5(data)
test_sha1(data)
test_sha256(data)
test_uuid(data)
- test_uuid4(data)
test_xxhash64(data)
test_xxhash128(data)
test_strhash32(data)
test_strhash128(data)
end
+
+function test_shortstr()
+ print("========================================== test short string ==========================================")
+ local data = ""
+ for i = 1, 10 do
+ data = data .. "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ end
+ test_md5(data)
+ test_sha1(data)
+ test_sha256(data)
+ test_uuid(data)
+ test_xxhash64(data)
+ test_xxhash128(data)
+ test_strhash32(data)
+ test_strhash128(data)
+end
+
+function main()
+ test_longstr()
+ test_shortstr()
+end