1
0
mirror of https://github.com/google/benchmark.git synced 2025-04-29 14:30:37 +08:00

Avoid potential truncation issues for the integral type parameterized tests. ()

* The parameterized tests check both floating point and integral types. We might as well use types that avoid truncation warnings across the platforms

* static_cast version of how to avoid truncation warnings in basic_test

Co-authored-by: Staffan Tjernstrom <staffantj@users.noreply.github.com>
This commit is contained in:
staffantj 2022-02-08 11:40:43 -05:00 committed by GitHub
parent bdea5051b0
commit d2cbd4b26a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -147,7 +147,7 @@ void BM_OneTemplateFunc(benchmark::State& state) {
auto arg = state.range(0);
T sum = 0;
for (auto _ : state) {
sum += arg;
sum += static_cast<T>(arg);
}
}
BENCHMARK(BM_OneTemplateFunc<int>)->Arg(1);
@ -159,8 +159,8 @@ void BM_TwoTemplateFunc(benchmark::State& state) {
A sum = 0;
B prod = 1;
for (auto _ : state) {
sum += arg;
prod *= arg;
sum += static_cast<A>(arg);
prod *= static_cast<B>(arg);
}
}
BENCHMARK(BM_TwoTemplateFunc<int, double>)->Arg(1);