forked from fortran-lang/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_64_bit_hash_performance.f90
executable file
·161 lines (134 loc) · 5.28 KB
/
test_64_bit_hash_performance.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
program test_64_bit_hash_performance
!! Program to compare the relative performance of different 64 bit hash
!! functions
use stdlib_kinds, only: &
dp, &
int8, &
int32, &
int64
use stdlib_hash_64bit
implicit none
integer, parameter :: &
block_size(8) = [ 1, 2, 4, 8, 16, 64, 256, 1024 ]
integer(int32), parameter :: huge32 = huge(0_int32)
real(dp), parameter :: hugep1 = real(huge32, dp) + 1.0_dp
integer, parameter :: rand_power = 16
integer, parameter :: rand_size = 2**rand_power
integer, parameter :: test_size = rand_size * 4
integer, parameter :: repeat = 4
integer :: index, k
integer :: lun
real(dp) :: rand(2)
integer(int32) :: rand_object(rand_size)
integer(int8) :: test_object(test_size)
open( newunit=lun, file="64_bit_hash_performance_log.txt", &
access="sequential", action="write", form="formatted", &
position="rewind" )
do index=1, rand_size
call random_number(rand)
if (rand(1) < 0.5_dp) then
rand_object(index) = ceiling(-rand(2)*hugep1, int32) - 1
else
rand_object(index) = floor(rand(2)*hugep1, int32)
end if
end do
test_object(:) = transfer( rand_object, 0_int8, test_size )
write(lun, '("| Algorithm | Key Size | Key # | Time (s) |")')
write(lun, '("| | Bytes | | |")')
write(lun, '("|------------|-----------|------------|----------|")')
call test_fnv_1()
call test_fnv_1a()
call test_pengy()
call test_spooky()
contains
subroutine test_fnv_1()
integer :: index2
integer(int64) :: hash
real :: t1, t2, tdiff
integer(int64) :: summary(repeat)
do k=1, size(block_size)
call cpu_time(t1)
do index=1, repeat
do index2=1, test_size, block_size(k)
hash = fnv_1_hash( test_object( index2: &
index2+block_size(k)-1 ) )
if (index2 == index) summary(index) = hash
end do
end do
call cpu_time(t2)
tdiff = t2-t1
write(lun, '("|", a10, 2x, "|", i8, 3x, "|", 1x, i10, 1x, ' // &
'"|", f9.5, 1x, "|")') 'FNV-1', &
block_size(k), repeat*(test_size/block_size(k)), tdiff
end do
end subroutine test_fnv_1
subroutine test_fnv_1a()
integer :: index2
integer(int64) :: hash
real :: t1, t2, tdiff
integer(int64) :: summary(repeat)
do k=1, size(block_size)
call cpu_time(t1)
do index=1, repeat
do index2=1, test_size, block_size(k)
hash = fnv_1a_hash( test_object( index2: &
index2+block_size(k)-1 ) )
if (index2 == index) summary(index) = hash
end do
end do
call cpu_time(t2)
tdiff = t2-t1
write(lun, '("|", a10, 2x, "|", i8, 3x, "|", 1x, i10, 1x, ' // &
'"|", f9.5, 1x, "|")') 'FNV-1a', &
block_size(k), repeat*(test_size/block_size(k)), tdiff
end do
end subroutine test_fnv_1a
subroutine test_spooky()
integer :: index2
integer(int64) :: hash(2)
integer(int64) :: seed(2) = [ 0_int64, 0_int64 ]
real :: t1, t2, tdiff
integer(int64) :: summary(repeat)
call new_spooky_hash_seed( seed )
do k=1, size(block_size)
call cpu_time(t1)
do index=1, repeat
do index2=1, test_size, block_size(k)
hash = spooky_hash( test_object( index2: &
index2+block_size(k)-1 ), &
seed )
if (index2 == index) summary(index) = hash(1)
end do
end do
call cpu_time(t2)
tdiff = t2-t1
write(lun, '("|", a10, 2x, "|", i8, 3x, "|", 1x, i10, 1x, ' // &
'"|", f9.5, 1x, "|")') 'Spooky', &
block_size(k), repeat*(test_size/block_size(k)), tdiff
end do
end subroutine test_spooky
subroutine test_pengy()
integer :: index2
integer(int64) :: hash
integer(int32) :: seed = int( z'DEADBEEF', int32 )
real :: t1, t2, tdiff
integer(int64) :: summary(repeat)
call new_pengy_hash_seed( seed )
do k=1, size(block_size)
call cpu_time(t1)
do index=1, repeat
do index2=1, test_size, block_size(k)
hash = pengy_hash( test_object( index2: &
index2+block_size(k)-1 ), &
seed )
if (index2 == index) summary(index) = hash
end do
end do
call cpu_time(t2)
tdiff = t2-t1
write(lun, '("|", a10, 2x, "|", i8, 3x, "|", 1x, i10, 1x, ' // &
'"|", f9.5, 1x, "|")') 'Pengy', &
block_size(k), repeat*(test_size/block_size(k)), tdiff
end do
end subroutine test_pengy
end program test_64_bit_hash_performance