You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BENCHMARK_CAPTURE(ToIntSimStr0, , stringa{" 123456789"}, 123456789) ->Name("stringa s = \" 123456789\"; int res = s.to_int<int>; // Check overflow");
288
280
BENCHMARK_CAPTURE(ToIntNoOverflow, , ssa{" 123456789"}, 123456789) ->Name("ssa s = \" 123456789\"; int res = s.to_int<int, false>; // No check overflow");
289
281
282
+
voidToDoubleStr(benchmark::State& state, const std::string& s, double c) {
283
+
for (auto _: state) {
284
+
char* ptr = nullptr;
285
+
double res = std::strtod(s.c_str(), &ptr);
286
+
if (ptr == s.c_str()) {
287
+
state.SkipWithError("not equal");
288
+
}
289
+
#ifdef CHECK_RESULT
290
+
if (res != c) {
291
+
state.SkipWithError("not equal");
292
+
break;
293
+
}
294
+
#endif
295
+
benchmark::DoNotOptimize(res);
296
+
}
297
+
}
298
+
299
+
voidToDoubleFromChars(benchmark::State& state, const std::string_view& s, double c) {
300
+
for (auto _: state) {
301
+
double res = 0;
302
+
if (std::from_chars(s.data(), s.data() + s.size(), res).ec != std::errc{}) {
303
+
state.SkipWithError("not equal");
304
+
}
305
+
#ifdef CHECK_RESULT
306
+
if (res != c) {
307
+
state.SkipWithError("not equal");
308
+
break;
309
+
}
310
+
#endif
311
+
benchmark::DoNotOptimize(res);
312
+
}
313
+
}
314
+
315
+
template<typename T>
316
+
voidToDoubleSimStr(benchmark::State& state, T t, double c) {
317
+
for (auto _: state) {
318
+
auto r = t.templateto_double<false>();
319
+
if (!r) {
320
+
state.SkipWithError("not equal");
321
+
}
322
+
double res = *r;
323
+
#ifdef CHECK_RESULT
324
+
if (res != c) {
325
+
state.SkipWithError("not equal");
326
+
break;
327
+
}
328
+
#endif
329
+
benchmark::DoNotOptimize(res);
330
+
benchmark::DoNotOptimize(t);
331
+
}
332
+
}
333
+
334
+
BENCHMARK(__)->Name("----- Convert to double '1234.567e10' ---------")->Repetitions(1);
335
+
BENCHMARK_CAPTURE(ToDoubleStr, , std::string{"1234.567e10"}, 1234.567e10) ->Name("std::string s = \"1234.567e10\"; double res = std::strtod(s.c_str(), nullptr);");
0 commit comments