DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
benchmarkHyperRectDomain.cpp
Go to the documentation of this file.
1
16
26
31
32
#include <iostream>
33
#include <numeric>
34
#include <chrono>
35
36
#include "DGtal/base/Common.h"
37
#include "DGtal/kernel/SpaceND.h"
38
#include "DGtal/kernel/PointVector.h"
39
#include "DGtal/kernel/domains/HyperRectDomain.h"
40
41
#include "DGtalCatch.h"
42
43
using namespace
DGtal
;
44
using namespace
std
;
45
47
auto
tic_timer
= std::chrono::high_resolution_clock::now();
48
50
void
tic
()
51
{
52
tic_timer
= std::chrono::high_resolution_clock::now();
53
}
54
56
double
toc
()
57
{
58
const
auto
toc_timer = std::chrono::high_resolution_clock::now();
59
const
std::chrono::duration<double> time_span = toc_timer -
tic_timer
;
60
return
time_span.count();
61
}
62
63
// Context for each benchmark
64
struct
BenchDomain
65
{
66
static
constexpr
std::size_t
dim
= 3;
67
static
constexpr
signed
long
long
int
size
= 200;
68
static
constexpr
std::size_t
N
= 100;
69
70
using
Space
=
DGtal::SpaceND<dim>
;
71
using
Point
=
Space::Point
;
72
using
Domain
=
DGtal::HyperRectDomain<Space>
;
73
74
BenchDomain
()
75
:
a
(
Point
::diagonal(0))
76
,
b
(
Point
::diagonal(
size
))
77
,
domain
(
Domain
(
a
,
b
))
78
,
dimensions
(
Point
::dimension)
79
{
80
std::iota(
dimensions
.begin(),
dimensions
.end(),
Dimension
(0));
81
}
82
83
Point
a
,
b
;
84
Domain
domain
;
85
std::vector<Point::Dimension>
dimensions
;
86
};
87
88
89
TEST_CASE_METHOD(
BenchDomain
,
"Benchmarking HyperRectDomain iterators using custom implementation"
)
90
{
91
SECTION
(
"Domain forward traversal"
)
92
{
93
Point
check;
94
double
duration;
95
96
for
(std::size_t i = 0; i < N; ++i)
97
{
98
tic
();
99
for
(
auto
const
& pt :
domain
)
100
check += pt;
101
duration =
toc
();
102
}
103
104
trace
.
info
() <<
"Domain traversal: "
<< duration <<
" s ; "
<< (
domain
.size()/duration*1e-9) <<
" Gpts/s ; check = "
<< check << std::endl;
105
}
106
107
SECTION
(
"Domain reverse traversal"
)
108
{
109
Point
check;
110
double
duration;
111
112
for
(std::size_t i = 0; i < N; ++i)
113
{
114
tic
();
115
for
(
auto
it =
domain
.rbegin(), it_end =
domain
.rend(); it != it_end; ++it)
116
check += *it;
117
duration =
toc
();
118
}
119
120
trace
.
info
() <<
"Domain reverse traversal: "
<< duration <<
" s ; "
<< (
domain
.size()/duration*1e-9) <<
" Gpts/s ; check = "
<< check << std::endl;
121
}
122
123
SECTION
(
"Benchmarking domain traversal using subRange"
)
124
{
125
Point
check;
126
double
duration;
127
128
for
(std::size_t i = 0; i < N; ++i)
129
{
130
tic
();
131
for
(
auto
const
& pt :
domain
.subRange(dimensions))
132
check += pt;
133
duration =
toc
();
134
}
135
136
trace
.
info
() <<
"Domain traversal using subRange: "
<< duration <<
" s ; "
<< (
domain
.size()/duration*1e-9) <<
" Gpts/s ; check = "
<< check << std::endl;
137
}
138
139
SECTION
(
"Benchmarking domain reverse traversal using subRange"
)
140
{
141
Point
check;
142
const
auto
range =
domain
.subRange(dimensions);
143
double
duration;
144
145
for
(std::size_t i = 0; i < N; ++i)
146
{
147
tic
();
148
for
(
auto
it = range.rbegin(), it_end = range.rend(); it != it_end; ++it)
149
check += *it;
150
duration =
toc
();
151
}
152
153
trace
.
info
() <<
"Domain reverse traversal using subRange: "
<< duration <<
" s ; "
<< (
domain
.size()/duration*1e-9) <<
" Gpts/s ; check = "
<< check << std::endl;
154
}
155
}
156
toc
double toc()
Ends timer and return elapsed time.
Definition
benchmarkHyperRectDomain.cpp:56
tic_timer
auto tic_timer
Timer used in tic and toc.
Definition
benchmarkHyperRectDomain.cpp:47
tic
void tic()
Starts timer.
Definition
benchmarkHyperRectDomain.cpp:50
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition
HyperRectDomain.h:100
DGtal::SpaceND
Definition
SpaceND.h:96
DGtal::SpaceND::Point
PointVector< dim, Integer > Point
Points in DGtal::SpaceND.
Definition
SpaceND.h:110
DGtal::Trace::info
std::ostream & info()
DGtal::Domain
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::Dimension
DGtal::uint32_t Dimension
Definition
Common.h:119
DGtal::trace
Trace trace
std
STL namespace.
BenchDomain
Definition
benchmarkHyperRectDomain-catch.cpp:48
BenchDomain::a
Point a
Definition
benchmarkHyperRectDomain-catch.cpp:65
BenchDomain::dimensions
std::vector< Point::Dimension > dimensions
Definition
benchmarkHyperRectDomain-catch.cpp:67
BenchDomain::BenchDomain
BenchDomain()
Definition
benchmarkHyperRectDomain.cpp:74
BenchDomain::Space
DGtal::SpaceND< dim > Space
Definition
benchmarkHyperRectDomain-catch.cpp:52
BenchDomain::dim
static constexpr std::size_t dim
Definition
benchmarkHyperRectDomain-catch.cpp:49
BenchDomain::b
Point b
Definition
benchmarkHyperRectDomain-catch.cpp:65
BenchDomain::Point
Space::Point Point
Definition
benchmarkHyperRectDomain-catch.cpp:53
BenchDomain::N
static constexpr std::size_t N
Definition
benchmarkHyperRectDomain.cpp:68
BenchDomain::Domain
DGtal::HyperRectDomain< Space > Domain
Definition
benchmarkHyperRectDomain-catch.cpp:54
BenchDomain::domain
Domain domain
Definition
benchmarkHyperRectDomain-catch.cpp:66
BenchDomain::size
static constexpr signed long long int size
Definition
benchmarkHyperRectDomain-catch.cpp:50
domain
Domain domain
Definition
testProjection.cpp:88
SECTION
SECTION("Testing constant forward iterators")
Definition
testSimpleRandomAccessRangeFromPoint.cpp:66
tests
benchmarks
kernel
benchmarkHyperRectDomain.cpp
Generated on
for DGtal by
1.18.0