2020-01-29 01:43:09 +03:00
|
|
|
module main
|
|
|
|
|
2020-04-26 09:32:05 +03:00
|
|
|
import hash.fnv1a
|
2020-07-18 15:27:57 +03:00
|
|
|
import hash as wyhash
|
2020-04-26 09:32:05 +03:00
|
|
|
import rand
|
|
|
|
import time
|
2020-01-29 01:43:09 +03:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
sample_size := 10000000
|
|
|
|
min_str_len := 20
|
|
|
|
max_str_len := 40
|
|
|
|
println('Generating $sample_size strings between $min_str_len - $max_str_len chars long...')
|
2020-04-26 14:49:31 +03:00
|
|
|
mut bytepile := []byte{}
|
2020-01-29 01:43:09 +03:00
|
|
|
for _ in 0 .. sample_size * max_str_len {
|
2020-06-09 16:06:07 +03:00
|
|
|
bytepile << byte(rand.int_in_range(40, 125))
|
2020-01-29 01:43:09 +03:00
|
|
|
}
|
2020-04-26 14:49:31 +03:00
|
|
|
mut str_lens := []int{}
|
2020-01-29 01:43:09 +03:00
|
|
|
for _ in 0 .. sample_size {
|
2020-06-09 16:06:07 +03:00
|
|
|
str_lens << rand.int_in_range(min_str_len, max_str_len)
|
2020-01-29 01:43:09 +03:00
|
|
|
}
|
|
|
|
println('Hashing each of the generated strings...')
|
|
|
|
t0 := time.ticks()
|
|
|
|
mut start_pos := 0
|
|
|
|
for len in str_lens {
|
|
|
|
end_pos := start_pos + len
|
|
|
|
str := string(bytepile[start_pos..end_pos],len)
|
2020-06-08 01:47:04 +03:00
|
|
|
wyhash.wyhash_c(&str.str, u64(str.len), 1)
|
2020-01-29 01:43:09 +03:00
|
|
|
start_pos = end_pos
|
|
|
|
}
|
|
|
|
t1 := time.ticks()
|
|
|
|
d1 := t1 - t0
|
|
|
|
println(' * wyhash4 C: ${d1}ms')
|
|
|
|
start_pos = 0
|
|
|
|
for len in str_lens {
|
|
|
|
end_pos := start_pos + len
|
|
|
|
str := string(bytepile[start_pos..end_pos],len)
|
2020-06-08 01:47:04 +03:00
|
|
|
wyhash.sum64_string(str, 1)
|
2020-01-29 01:43:09 +03:00
|
|
|
start_pos = end_pos
|
|
|
|
}
|
|
|
|
t2 := time.ticks()
|
|
|
|
d2 := t2 - t1
|
|
|
|
println(' * wyhash4: ${d2}ms')
|
|
|
|
start_pos = 0
|
|
|
|
for len in str_lens {
|
|
|
|
end_pos := start_pos + len
|
|
|
|
str := string(bytepile[start_pos..end_pos],len)
|
2020-06-08 01:47:04 +03:00
|
|
|
fnv1a.sum64_string(str)
|
2020-01-29 01:43:09 +03:00
|
|
|
start_pos = end_pos
|
|
|
|
}
|
|
|
|
t3 := time.ticks()
|
|
|
|
d3 := t3 - t2
|
|
|
|
println(' * fnv1a64: ${d3}ms')
|
|
|
|
}
|