1515#include < hash.h>
1616#include < hash_x11.h>
1717#include < random.h>
18+ #include < tinyformat.h>
1819#include < uint256.h>
1920
2021/* Number of bytes to hash per iteration */
@@ -38,13 +39,48 @@ static void SHA1(benchmark::Bench& bench)
3839 });
3940}
4041
41- static void SHA256 (benchmark::Bench& bench)
42+ static void SHA256_STANDARD (benchmark::Bench& bench)
4243{
44+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::STANDARD)));
4345 uint8_t hash[CSHA256::OUTPUT_SIZE];
4446 std::vector<uint8_t > in (BUFFER_SIZE,0 );
4547 bench.batch (in.size ()).unit (" byte" ).run ([&] {
4648 CSHA256 ().Write (in.data (), in.size ()).Finalize (hash);
4749 });
50+ SHA256AutoDetect ();
51+ }
52+
53+ static void SHA256_SSE4 (benchmark::Bench& bench)
54+ {
55+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4)));
56+ uint8_t hash[CSHA256::OUTPUT_SIZE];
57+ std::vector<uint8_t > in (BUFFER_SIZE,0 );
58+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
59+ CSHA256 ().Write (in.data (), in.size ()).Finalize (hash);
60+ });
61+ SHA256AutoDetect ();
62+ }
63+
64+ static void SHA256_AVX2 (benchmark::Bench& bench)
65+ {
66+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_AVX2)));
67+ uint8_t hash[CSHA256::OUTPUT_SIZE];
68+ std::vector<uint8_t > in (BUFFER_SIZE,0 );
69+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
70+ CSHA256 ().Write (in.data (), in.size ()).Finalize (hash);
71+ });
72+ SHA256AutoDetect ();
73+ }
74+
75+ static void SHA256_SHANI (benchmark::Bench& bench)
76+ {
77+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_SHANI)));
78+ uint8_t hash[CSHA256::OUTPUT_SIZE];
79+ std::vector<uint8_t > in (BUFFER_SIZE,0 );
80+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
81+ CSHA256 ().Write (in.data (), in.size ()).Finalize (hash);
82+ });
83+ SHA256AutoDetect ();
4884}
4985
5086static void SHA3_256_1M (benchmark::Bench& bench)
@@ -56,22 +92,92 @@ static void SHA3_256_1M(benchmark::Bench& bench)
5692 });
5793}
5894
59- static void SHA256_32b (benchmark::Bench& bench)
95+ static void SHA256_32b_STANDARD (benchmark::Bench& bench)
96+ {
97+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::STANDARD)));
98+ std::vector<uint8_t > in (32 ,0 );
99+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
100+ CSHA256 ()
101+ .Write (in.data (), in.size ())
102+ .Finalize (in.data ());
103+ });
104+ SHA256AutoDetect ();
105+ }
106+
107+ static void SHA256_32b_SSE4 (benchmark::Bench& bench)
108+ {
109+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4)));
110+ std::vector<uint8_t > in (32 ,0 );
111+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
112+ CSHA256 ()
113+ .Write (in.data (), in.size ())
114+ .Finalize (in.data ());
115+ });
116+ SHA256AutoDetect ();
117+ }
118+
119+ static void SHA256_32b_AVX2 (benchmark::Bench& bench)
120+ {
121+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_AVX2)));
122+ std::vector<uint8_t > in (32 ,0 );
123+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
124+ CSHA256 ()
125+ .Write (in.data (), in.size ())
126+ .Finalize (in.data ());
127+ });
128+ SHA256AutoDetect ();
129+ }
130+
131+ static void SHA256_32b_SHANI (benchmark::Bench& bench)
60132{
133+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_SHANI)));
61134 std::vector<uint8_t > in (32 ,0 );
62135 bench.batch (in.size ()).unit (" byte" ).run ([&] {
63136 CSHA256 ()
64137 .Write (in.data (), in.size ())
65138 .Finalize (in.data ());
66139 });
140+ SHA256AutoDetect ();
141+ }
142+
143+ static void SHA256D64_1024_STANDARD (benchmark::Bench& bench)
144+ {
145+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::STANDARD)));
146+ std::vector<uint8_t > in (64 * 1024 , 0 );
147+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
148+ SHA256D64 (in.data (), in.data (), 1024 );
149+ });
150+ SHA256AutoDetect ();
151+ }
152+
153+ static void SHA256D64_1024_SSE4 (benchmark::Bench& bench)
154+ {
155+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4)));
156+ std::vector<uint8_t > in (64 * 1024 , 0 );
157+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
158+ SHA256D64 (in.data (), in.data (), 1024 );
159+ });
160+ SHA256AutoDetect ();
161+ }
162+
163+ static void SHA256D64_1024_AVX2 (benchmark::Bench& bench)
164+ {
165+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_AVX2)));
166+ std::vector<uint8_t > in (64 * 1024 , 0 );
167+ bench.batch (in.size ()).unit (" byte" ).run ([&] {
168+ SHA256D64 (in.data (), in.data (), 1024 );
169+ });
170+ SHA256AutoDetect ();
67171}
68172
69- static void SHA256D64_1024 (benchmark::Bench& bench)
173+ static void SHA256D64_1024_SHANI (benchmark::Bench& bench)
70174{
175+ bench.name (strprintf (" %s using the '%s' SHA256 implementation" , __func__, SHA256AutoDetect (sha256_implementation::USE_SSE4_AND_SHANI)));
71176 std::vector<uint8_t > in (64 * 1024 , 0 );
72177 bench.batch (in.size ()).unit (" byte" ).run ([&] {
73178 SHA256D64 (in.data (), in.data (), 1024 );
74179 });
180+ SHA256AutoDetect ();
75181}
76182
77183static void SHA512 (benchmark::Bench& bench)
@@ -154,13 +260,22 @@ static void MuHashPrecompute(benchmark::Bench& bench)
154260
155261BENCHMARK (BenchRIPEMD160);
156262BENCHMARK (SHA1);
157- BENCHMARK (SHA256);
263+ BENCHMARK (SHA256_STANDARD);
264+ BENCHMARK (SHA256_SSE4);
265+ BENCHMARK (SHA256_AVX2);
266+ BENCHMARK (SHA256_SHANI);
158267BENCHMARK (SHA512);
159268BENCHMARK (SHA3_256_1M);
160269
161- BENCHMARK (SHA256_32b);
270+ BENCHMARK (SHA256_32b_STANDARD);
271+ BENCHMARK (SHA256_32b_SSE4);
272+ BENCHMARK (SHA256_32b_AVX2);
273+ BENCHMARK (SHA256_32b_SHANI);
162274BENCHMARK (SipHash_32b);
163- BENCHMARK (SHA256D64_1024);
275+ BENCHMARK (SHA256D64_1024_STANDARD);
276+ BENCHMARK (SHA256D64_1024_SSE4);
277+ BENCHMARK (SHA256D64_1024_AVX2);
278+ BENCHMARK (SHA256D64_1024_SHANI);
164279BENCHMARK (FastRandom_32bit);
165280BENCHMARK (FastRandom_1bit);
166281
0 commit comments