cmd/tools/bench/wyhash.v: minor cleanup of output
parent
df5625bf68
commit
f605022481
|
@ -3,15 +3,17 @@ module main
|
||||||
import hash.fnv1a
|
import hash.fnv1a
|
||||||
import hash as wyhash
|
import hash as wyhash
|
||||||
import rand
|
import rand
|
||||||
import time
|
import benchmark
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rand.seed([u32(42), 0])
|
rand.seed([u32(42), 0])
|
||||||
mut aaa := u64(0)
|
|
||||||
sample_size := 10000000
|
sample_size := 10000000
|
||||||
min_str_len := 20
|
min_str_len := 20
|
||||||
max_str_len := 40
|
max_str_len := 40
|
||||||
println('Generating $sample_size strings between $min_str_len - $max_str_len chars long...')
|
println('Generating $sample_size strings between $min_str_len - $max_str_len chars long...')
|
||||||
|
mut checksum := u64(0)
|
||||||
|
mut start_pos := 0
|
||||||
|
mut bgenerating := benchmark.start()
|
||||||
mut bytepile := []byte{}
|
mut bytepile := []byte{}
|
||||||
for _ in 0 .. sample_size * max_str_len {
|
for _ in 0 .. sample_size * max_str_len {
|
||||||
bytepile << byte(rand.int_in_range(40, 125))
|
bytepile << byte(rand.int_in_range(40, 125))
|
||||||
|
@ -20,42 +22,37 @@ fn main() {
|
||||||
for _ in 0 .. sample_size {
|
for _ in 0 .. sample_size {
|
||||||
str_lens << rand.int_in_range(min_str_len, max_str_len)
|
str_lens << rand.int_in_range(min_str_len, max_str_len)
|
||||||
}
|
}
|
||||||
|
bgenerating.measure('generating strings')
|
||||||
println('Hashing each of the generated strings...')
|
println('Hashing each of the generated strings...')
|
||||||
t0 := time.ticks()
|
//
|
||||||
mut start_pos := 0
|
mut bhashing_1 := benchmark.start()
|
||||||
aaa = 0
|
|
||||||
for len in str_lens {
|
|
||||||
end_pos := start_pos + len
|
|
||||||
str := string(bytepile[start_pos..end_pos], len)
|
|
||||||
aaa ^= wyhash.wyhash_c(&str.str, u64(str.len), 1)
|
|
||||||
start_pos = end_pos
|
|
||||||
}
|
|
||||||
println('aaa: $aaa')
|
|
||||||
t1 := time.ticks()
|
|
||||||
d1 := t1 - t0
|
|
||||||
println(' * wyhash4 C: ${d1}ms')
|
|
||||||
start_pos = 0
|
start_pos = 0
|
||||||
aaa = 0
|
checksum = 0
|
||||||
for len in str_lens {
|
for len in str_lens {
|
||||||
end_pos := start_pos + len
|
end_pos := start_pos + len
|
||||||
str := string(bytepile[start_pos..end_pos], len)
|
str := string(bytepile[start_pos..end_pos], len)
|
||||||
aaa ^= wyhash.sum64_string(str, 1)
|
checksum ^= wyhash.wyhash_c(&str.str, u64(str.len), 1)
|
||||||
start_pos = end_pos
|
start_pos = end_pos
|
||||||
}
|
}
|
||||||
println('aaa: $aaa')
|
bhashing_1.measure('wyhash.wyhash_c | checksum: ${checksum:22}')
|
||||||
t2 := time.ticks()
|
mut bhashing_2 := benchmark.start()
|
||||||
d2 := t2 - t1
|
|
||||||
println(' * wyhash4: ${d2}ms')
|
|
||||||
start_pos = 0
|
start_pos = 0
|
||||||
aaa = 0
|
checksum = 0
|
||||||
for len in str_lens {
|
for len in str_lens {
|
||||||
end_pos := start_pos + len
|
end_pos := start_pos + len
|
||||||
str := string(bytepile[start_pos..end_pos], len)
|
str := string(bytepile[start_pos..end_pos], len)
|
||||||
aaa ^= fnv1a.sum64_string(str)
|
checksum ^= wyhash.sum64_string(str, 1)
|
||||||
start_pos = end_pos
|
start_pos = end_pos
|
||||||
}
|
}
|
||||||
println('aaa: $aaa')
|
bhashing_2.measure('wyhash.sum64_string | checksum: ${checksum:22}')
|
||||||
t3 := time.ticks()
|
mut bhashing_3 := benchmark.start()
|
||||||
d3 := t3 - t2
|
start_pos = 0
|
||||||
println(' * fnv1a64: ${d3}ms')
|
checksum = 0
|
||||||
|
for len in str_lens {
|
||||||
|
end_pos := start_pos + len
|
||||||
|
str := string(bytepile[start_pos..end_pos], len)
|
||||||
|
checksum ^= fnv1a.sum64_string(str)
|
||||||
|
start_pos = end_pos
|
||||||
|
}
|
||||||
|
bhashing_3.measure('fnv1a.sum64_string | checksum: ${checksum:22}')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue