DGtal  1.5.beta
benchmarkHyperRectDomain.cpp File Reference
#include <iostream>
#include <numeric>
#include <chrono>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/PointVector.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtalCatch.h"
Include dependency graph for benchmarkHyperRectDomain.cpp:

Go to the source code of this file.

Functions

void tic ()
 Starts timer. More...
 
double toc ()
 Ends timer and return elapsed time. More...
 
 TEST_CASE_METHOD (BenchDomain, "Benchmarking HyperRectDomain iterators using custom implementation")
 

Variables

auto tic_timer = std::chrono::high_resolution_clock::now()
 Timer used in tic and toc. More...
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Roland Denis (rolan.nosp@m.d.de.nosp@m.nis@m.nosp@m.ath..nosp@m.univ-.nosp@m.lyon.nosp@m.1.fr )
Date
2019/10/14

This file is part of the DGtal library

Definition in file benchmarkHyperRectDomain.cpp.

Function Documentation

◆ TEST_CASE_METHOD()

TEST_CASE_METHOD ( BenchDomain  ,
"Benchmarking HyperRectDomain iterators using custom implementation"   
)

Definition at line 89 of file benchmarkHyperRectDomain.cpp.

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 }
double toc()
Ends timer and return elapsed time.
void tic()
Starts timer.
ConstReverseIterator rbegin() const
ConstSubRange subRange(const std::vector< Dimension > &permutation) const
ConstReverseIterator rend() const
std::ostream & info()
Trace trace
Definition: Common.h:153
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
SECTION("Testing constant forward iterators")

References domain, DGtal::Trace::info(), DGtal::HyperRectDomain< TSpace >::rbegin(), DGtal::HyperRectDomain< TSpace >::rend(), SECTION(), DGtal::HyperRectDomain< TSpace >::size(), DGtal::HyperRectDomain< TSpace >::subRange(), tic(), toc(), and DGtal::trace.

◆ tic()

void tic ( )

Starts timer.

Definition at line 50 of file benchmarkHyperRectDomain.cpp.

51 {
52  tic_timer = std::chrono::high_resolution_clock::now();
53 }
auto tic_timer
Timer used in tic and toc.

References tic_timer.

Referenced by DGtal::QuickHull< TKernel >::computeConvexHull(), DGtal::QuickHull< TKernel >::setInput(), and TEST_CASE_METHOD().

◆ toc()

double toc ( )

Ends timer and return elapsed time.

Definition at line 56 of file benchmarkHyperRectDomain.cpp.

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 }

References tic_timer.

Referenced by TEST_CASE_METHOD().

Variable Documentation

◆ tic_timer

auto tic_timer = std::chrono::high_resolution_clock::now()

Timer used in tic and toc.

Definition at line 47 of file benchmarkHyperRectDomain.cpp.

Referenced by tic(), and toc().