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. (#1341)
* 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:
parent
bdea5051b0
commit
d2cbd4b26a
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user