13
13
#include < crypto/siphash.h>
14
14
#include < hash.h>
15
15
#include < random.h>
16
+ #include < tinyformat.h>
16
17
#include < uint256.h>
17
18
18
19
/* Number of bytes to hash per iteration */
@@ -36,13 +37,48 @@ static void SHA1(benchmark::Bench& bench)
36
37
});
37
38
}
38
39
39
- static void SHA256 (benchmark::Bench& bench)
40
+ static void SHA256_STANDARD (benchmark::Bench& bench)
40
41
{
42
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::STANDARD)));
41
43
uint8_t hash[CSHA256::OUTPUT_SIZE];
42
44
std::vector<uint8_t > in (BUFFER_SIZE,0 );
43
45
bench.batch (in.size ()).unit (" byte" ).run ([&] {
44
46
CSHA256 ().Write (in.data (), in.size ()).Finalize (hash);
45
47
});
48
+ SHA256AutoDetect ();
49
+ }
50
+
51
+ static void SHA256_SSE4 (benchmark::Bench& bench)
52
+ {
53
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4)));
54
+ uint8_t hash[CSHA256::OUTPUT_SIZE];
55
+ std::vector<uint8_t > in (BUFFER_SIZE,0 );
56
+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
57
+ CSHA256 ().Write (in.data (), in.size ()).Finalize (hash);
58
+ });
59
+ SHA256AutoDetect ();
60
+ }
61
+
62
+ static void SHA256_AVX2 (benchmark::Bench& bench)
63
+ {
64
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_AVX2)));
65
+ uint8_t hash[CSHA256::OUTPUT_SIZE];
66
+ std::vector<uint8_t > in (BUFFER_SIZE,0 );
67
+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
68
+ CSHA256 ().Write (in.data (), in.size ()).Finalize (hash);
69
+ });
70
+ SHA256AutoDetect ();
71
+ }
72
+
73
+ static void SHA256_SHANI (benchmark::Bench& bench)
74
+ {
75
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_SHANI)));
76
+ uint8_t hash[CSHA256::OUTPUT_SIZE];
77
+ std::vector<uint8_t > in (BUFFER_SIZE,0 );
78
+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
79
+ CSHA256 ().Write (in.data (), in.size ()).Finalize (hash);
80
+ });
81
+ SHA256AutoDetect ();
46
82
}
47
83
48
84
static void SHA3_256_1M (benchmark::Bench& bench)
@@ -54,22 +90,92 @@ static void SHA3_256_1M(benchmark::Bench& bench)
54
90
});
55
91
}
56
92
57
- static void SHA256_32b (benchmark::Bench& bench)
93
+ static void SHA256_32b_STANDARD (benchmark::Bench& bench)
94
+ {
95
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::STANDARD)));
96
+ std::vector<uint8_t > in (32 ,0 );
97
+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
98
+ CSHA256 ()
99
+ .Write (in.data (), in.size ())
100
+ .Finalize (in.data ());
101
+ });
102
+ SHA256AutoDetect ();
103
+ }
104
+
105
+ static void SHA256_32b_SSE4 (benchmark::Bench& bench)
106
+ {
107
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4)));
108
+ std::vector<uint8_t > in (32 ,0 );
109
+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
110
+ CSHA256 ()
111
+ .Write (in.data (), in.size ())
112
+ .Finalize (in.data ());
113
+ });
114
+ SHA256AutoDetect ();
115
+ }
116
+
117
+ static void SHA256_32b_AVX2 (benchmark::Bench& bench)
118
+ {
119
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_AVX2)));
120
+ std::vector<uint8_t > in (32 ,0 );
121
+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
122
+ CSHA256 ()
123
+ .Write (in.data (), in.size ())
124
+ .Finalize (in.data ());
125
+ });
126
+ SHA256AutoDetect ();
127
+ }
128
+
129
+ static void SHA256_32b_SHANI (benchmark::Bench& bench)
58
130
{
131
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_SHANI)));
59
132
std::vector<uint8_t > in (32 ,0 );
60
133
bench.batch (in.size ()).unit (" byte" ).run ([&] {
61
134
CSHA256 ()
62
135
.Write (in.data (), in.size ())
63
136
.Finalize (in.data ());
64
137
});
138
+ SHA256AutoDetect ();
139
+ }
140
+
141
+ static void SHA256D64_1024_STANDARD (benchmark::Bench& bench)
142
+ {
143
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::STANDARD)));
144
+ std::vector<uint8_t > in (64 * 1024 , 0 );
145
+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
146
+ SHA256D64 (in.data (), in.data (), 1024 );
147
+ });
148
+ SHA256AutoDetect ();
149
+ }
150
+
151
+ static void SHA256D64_1024_SSE4 (benchmark::Bench& bench)
152
+ {
153
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4)));
154
+ std::vector<uint8_t > in (64 * 1024 , 0 );
155
+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
156
+ SHA256D64 (in.data (), in.data (), 1024 );
157
+ });
158
+ SHA256AutoDetect ();
159
+ }
160
+
161
+ static void SHA256D64_1024_AVX2 (benchmark::Bench& bench)
162
+ {
163
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_AVX2)));
164
+ std::vector<uint8_t > in (64 * 1024 , 0 );
165
+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
166
+ SHA256D64 (in.data (), in.data (), 1024 );
167
+ });
168
+ SHA256AutoDetect ();
65
169
}
66
170
67
- static void SHA256D64_1024 (benchmark::Bench& bench)
171
+ static void SHA256D64_1024_SHANI (benchmark::Bench& bench)
68
172
{
173
+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_SHANI)));
69
174
std::vector<uint8_t > in (64 * 1024 , 0 );
70
175
bench.batch (in.size ()).unit (" byte" ).run ([&] {
71
176
SHA256D64 (in.data (), in.data (), 1024 );
72
177
});
178
+ SHA256AutoDetect ();
73
179
}
74
180
75
181
static void SHA512 (benchmark::Bench& bench)
@@ -152,13 +258,22 @@ static void MuHashPrecompute(benchmark::Bench& bench)
152
258
153
259
BENCHMARK (BenchRIPEMD160, benchmark::PriorityLevel::HIGH);
154
260
BENCHMARK (SHA1, benchmark::PriorityLevel::HIGH);
155
- BENCHMARK (SHA256, benchmark::PriorityLevel::HIGH);
261
+ BENCHMARK (SHA256_STANDARD, benchmark::PriorityLevel::HIGH);
262
+ BENCHMARK (SHA256_SSE4, benchmark::PriorityLevel::HIGH);
263
+ BENCHMARK (SHA256_AVX2, benchmark::PriorityLevel::HIGH);
264
+ BENCHMARK (SHA256_SHANI, benchmark::PriorityLevel::HIGH);
156
265
BENCHMARK (SHA512, benchmark::PriorityLevel::HIGH);
157
266
BENCHMARK (SHA3_256_1M, benchmark::PriorityLevel::HIGH);
158
267
159
- BENCHMARK (SHA256_32b, benchmark::PriorityLevel::HIGH);
268
+ BENCHMARK (SHA256_32b_STANDARD, benchmark::PriorityLevel::HIGH);
269
+ BENCHMARK (SHA256_32b_SSE4, benchmark::PriorityLevel::HIGH);
270
+ BENCHMARK (SHA256_32b_AVX2, benchmark::PriorityLevel::HIGH);
271
+ BENCHMARK (SHA256_32b_SHANI, benchmark::PriorityLevel::HIGH);
160
272
BENCHMARK (SipHash_32b, benchmark::PriorityLevel::HIGH);
161
- BENCHMARK (SHA256D64_1024, benchmark::PriorityLevel::HIGH);
273
+ BENCHMARK (SHA256D64_1024_STANDARD, benchmark::PriorityLevel::HIGH);
274
+ BENCHMARK (SHA256D64_1024_SSE4, benchmark::PriorityLevel::HIGH);
275
+ BENCHMARK (SHA256D64_1024_AVX2, benchmark::PriorityLevel::HIGH);
276
+ BENCHMARK (SHA256D64_1024_SHANI, benchmark::PriorityLevel::HIGH);
162
277
BENCHMARK (FastRandom_32bit, benchmark::PriorityLevel::HIGH);
163
278
BENCHMARK (FastRandom_1bit, benchmark::PriorityLevel::HIGH);
164
279
0 commit comments