@@ -58,6 +58,36 @@ void BM_WebSafeBase64Escape_string(benchmark::State& state) {
58
58
}
59
59
BENCHMARK (BM_WebSafeBase64Escape_string);
60
60
61
+ void BM_HexStringToBytes (benchmark::State& state) {
62
+ const int size = state.range (0 );
63
+ std::string input, output;
64
+ for (int i = 0 ; i < size; ++i) input += " 1c" ;
65
+ for (auto _ : state) {
66
+ benchmark::DoNotOptimize (input);
67
+ bool result = absl::HexStringToBytes (input, &output);
68
+ benchmark::DoNotOptimize (result);
69
+ benchmark::DoNotOptimize (output);
70
+ }
71
+ }
72
+ BENCHMARK (BM_HexStringToBytes)->Range (1 , 1 << 8 );
73
+
74
+ void BM_HexStringToBytes_Fail (benchmark::State& state) {
75
+ std::string binary;
76
+ absl::string_view hex_input1 = " 1c2f003" ;
77
+ absl::string_view hex_input2 = " 1c2f0032f40123456789abcdef**" ;
78
+ for (auto _ : state) {
79
+ benchmark::DoNotOptimize (hex_input1);
80
+ bool result1 = absl::HexStringToBytes (hex_input1, &binary);
81
+ benchmark::DoNotOptimize (result1);
82
+ benchmark::DoNotOptimize (binary);
83
+ benchmark::DoNotOptimize (hex_input2);
84
+ bool result2 = absl::HexStringToBytes (hex_input2, &binary);
85
+ benchmark::DoNotOptimize (result2);
86
+ benchmark::DoNotOptimize (binary);
87
+ }
88
+ }
89
+ BENCHMARK (BM_HexStringToBytes_Fail);
90
+
61
91
// Used for the CEscape benchmarks
62
92
const char kStringValueNoEscape [] = " 1234567890" ;
63
93
const char kStringValueSomeEscaped [] = " 123\n 56789\xA1 " ;
0 commit comments