-
Notifications
You must be signed in to change notification settings - Fork 915
/
convert_durations_benchmark.cpp
112 lines (93 loc) · 4.69 KB
/
convert_durations_benchmark.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <benchmark/benchmark.h>
#include <cudf/strings/convert/convert_durations.hpp>
#include <cudf/types.hpp>
#include <tests/utilities/base_fixture.hpp>
#include <tests/utilities/column_utilities.hpp>
#include <tests/utilities/column_wrapper.hpp>
#include <tests/utilities/cudf_gtest.hpp>
#include <algorithm>
#include <random>
#include "../fixture/benchmark_fixture.hpp"
#include "../synchronization/synchronization.hpp"
#include "cudf/column/column_view.hpp"
#include "cudf/wrappers/durations.hpp"
class DurationsToString : public cudf::benchmark {
};
template <class TypeParam>
void BM_convert_from_durations(benchmark::State& state)
{
const cudf::size_type source_size = state.range(0);
// Every element is valid
auto data = cudf::test::make_counting_transform_iterator(
0, [source_size](auto i) { return TypeParam{i - source_size / 2}; });
cudf::test::fixed_width_column_wrapper<TypeParam> source_durations(data, data + source_size);
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf::strings::from_durations(source_durations, "%D days %H:%M:%S");
}
state.SetBytesProcessed(state.iterations() * source_size * sizeof(TypeParam));
}
class StringToDurations : public cudf::benchmark {
};
template <class TypeParam>
void BM_convert_to_durations(benchmark::State& state)
{
const cudf::size_type source_size = state.range(0);
// Every element is valid
auto data = cudf::test::make_counting_transform_iterator(
0, [source_size](auto i) { return TypeParam{i - source_size / 2}; });
cudf::test::fixed_width_column_wrapper<TypeParam> source_durations(data, data + source_size);
auto results = cudf::strings::from_durations(source_durations, "%D days %H:%M:%S");
cudf::strings_column_view source_string(*results);
auto output_type = cudf::data_type(cudf::type_to_id<TypeParam>());
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf::strings::to_durations(source_string, output_type, "%D days %H:%M:%S");
}
state.SetBytesProcessed(state.iterations() * source_size * sizeof(TypeParam));
}
#define DSBM_BENCHMARK_DEFINE(name, type) \
BENCHMARK_DEFINE_F(DurationsToString, name)(::benchmark::State & state) \
{ \
BM_convert_from_durations<type>(state); \
} \
BENCHMARK_REGISTER_F(DurationsToString, name) \
->RangeMultiplier(1 << 5) \
->Range(1 << 10, 1 << 25) \
->UseManualTime() \
->Unit(benchmark::kMicrosecond);
#define SDBM_BENCHMARK_DEFINE(name, type) \
BENCHMARK_DEFINE_F(StringToDurations, name)(::benchmark::State & state) \
{ \
BM_convert_to_durations<type>(state); \
} \
BENCHMARK_REGISTER_F(StringToDurations, name) \
->RangeMultiplier(1 << 5) \
->Range(1 << 10, 1 << 25) \
->UseManualTime() \
->Unit(benchmark::kMicrosecond);
DSBM_BENCHMARK_DEFINE(from_durations_D, cudf::duration_D);
DSBM_BENCHMARK_DEFINE(from_durations_s, cudf::duration_s);
DSBM_BENCHMARK_DEFINE(from_durations_ms, cudf::duration_ms);
DSBM_BENCHMARK_DEFINE(from_durations_us, cudf::duration_us);
DSBM_BENCHMARK_DEFINE(from_durations_ns, cudf::duration_ns);
SDBM_BENCHMARK_DEFINE(to_durations_D, cudf::duration_D);
SDBM_BENCHMARK_DEFINE(to_durations_s, cudf::duration_s);
SDBM_BENCHMARK_DEFINE(to_durations_ms, cudf::duration_ms);
SDBM_BENCHMARK_DEFINE(to_durations_us, cudf::duration_us);
SDBM_BENCHMARK_DEFINE(to_durations_ns, cudf::duration_ns);