diff options
| author | ruki <[email protected]> | 2025-10-01 00:36:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-10-01 00:36:38 +0800 |
| commit | e4a2d682015b651adfcf7d7494a295c3276d7f10 (patch) | |
| tree | 208f1fc98dec6ea1baeb3dbd294bea3697d30349 /tests/benchmarks/hash.lua | |
| parent | b86ebe99285371dcdf08483208b7de70a7b8b050 (diff) | |
add hash.random32/64/128
Diffstat (limited to 'tests/benchmarks/hash.lua')
| -rw-r--r-- | tests/benchmarks/hash.lua | 84 |
1 files changed, 82 insertions, 2 deletions
diff --git a/tests/benchmarks/hash.lua b/tests/benchmarks/hash.lua index 48c360d58..ee23921c6 100644 --- a/tests/benchmarks/hash.lua +++ b/tests/benchmarks/hash.lua @@ -49,6 +49,18 @@ function test_uuid(data) print("uuid(%d): %d ms, hash: %s", COUNT, t * 10000, h) end +function test_xxhash32(data) + data = bytes(data) + local h + local n = COUNT / 10 + local t = os.mclock() + for i = 1, n do + h = hash.xxhash32(data) + end + t = os.mclock() - t + print("xxhash32(%d): %d ms, hash: %s", COUNT, t * 10, h) +end + function test_xxhash64(data) data = bytes(data) local h @@ -84,6 +96,17 @@ function test_strhash32(data) print("strhash32(%d): %d ms, hash: %s", COUNT, t * 10, h) end +function test_strhash64(data) + local h + local n = COUNT / 10 + local t = os.mclock() + for i = 1, n do + h = hash.strhash64(data) + end + t = os.mclock() - t + print("strhash64(%d): %d ms, hash: %s", COUNT, t * 10, h) +end + function test_strhash128(data) local h local n = COUNT / 10 @@ -95,6 +118,50 @@ function test_strhash128(data) print("strhash128(%d): %d ms, hash: %s", COUNT, t * 10, h) end +function test_random_uuid() + local h + local n = COUNT / 10 + local t = os.mclock() + for i = 1, n do + h = hash.uuid() + end + t = os.mclock() - t + print("uuid(%d): %d ms, hash: %s", COUNT, t * 10, h) +end + +function test_random32() + local h + local n = COUNT / 10 + local t = os.mclock() + for i = 1, n do + h = hash.random32() + end + t = os.mclock() - t + print("random32(%d): %d ms, hash: %s", COUNT, t * 10, h) +end + +function test_random64() + local h + local n = COUNT / 10 + local t = os.mclock() + for i = 1, n do + h = hash.random64() + end + t = os.mclock() - t + print("random64(%d): %d ms, hash: %s", COUNT, t * 10, h) +end + +function test_random128() + local h + local n = COUNT / 10 + local t = os.mclock() + for i = 1, n do + h = hash.random128() + end + t = os.mclock() - t + print("random128(%d): %d ms, hash: %s", COUNT, t * 10, h) +end + function test_longstr() print("========================================== test long string ==========================================") local data = "" @@ -105,9 +172,11 @@ function test_longstr() test_sha1(data) test_sha256(data) test_uuid(data) + test_xxhash32(data) test_xxhash64(data) test_xxhash128(data) test_strhash32(data) + test_strhash64(data) test_strhash128(data) end @@ -122,13 +191,24 @@ function test_shortstr() test_sha1(data) test_sha256(data) test_uuid(data) + test_xxhash32(data) test_xxhash64(data) test_xxhash128(data) test_strhash32(data) + test_strhash64(data) test_strhash128(data) end +function test_random() + print("========================================== test random ==========================================") + test_random_uuid() + test_random32() + test_random64() + test_random128() +end + function main() - test_longstr() - test_shortstr() +-- test_longstr() +-- test_shortstr() + test_random() end |
