MOTION  0.01
Framework for mixed-protocol multi-party computation
run_time_statistics.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Lennart Braun
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <array>
26 #include <chrono>
27 #include <string>
28 #include <utility>
29 
30 namespace encrypto::motion {
31 
33  using ClockType = std::chrono::steady_clock;
34  using TimePoint = std::chrono::time_point<ClockType>;
35  using TimePointPair = std::pair<TimePoint, TimePoint>;
36 
37  enum class StatisticsId : std::size_t {
39  kMtSetup,
41  kSbSetup,
43  kSpSetup,
45  kPreprocessing, // MTs, OTs etc.
48  kEvaluate,
49  kBaseOts,
50  kMax // maximal value of this Enum, use as size
51  };
52 
53  TimePoint GetTime() { return ClockType::now(); }
54 
55  template <StatisticsId Id>
56  void RecordStart() {
57  data[static_cast<std::size_t>(Id)].first = ClockType::now();
58  // data.at(static_cast<std::size_t>(Id)).first = ClockType::now();
59  }
60 
61  template <StatisticsId Id>
62  void RecordEnd() {
63  data[static_cast<std::size_t>(Id)].second = ClockType::now();
64  // data.at(static_cast<std::size_t>(Id)).second = ClockType::now();
65  }
66 
67  const TimePointPair& Get(StatisticsId id) const;
68 
69  std::string PrintHumanReadable() const;
70 
71  std::array<TimePointPair, static_cast<std::size_t>(StatisticsId::kMax) + 1> data;
72 };
73 
74 } // namespace encrypto::motion
encrypto::motion::RunTimeStatistics::RecordEnd
void RecordEnd()
Definition: run_time_statistics.h:62
encrypto::motion::RunTimeStatistics::TimePointPair
std::pair< TimePoint, TimePoint > TimePointPair
Definition: run_time_statistics.h:35
encrypto::motion::RunTimeStatistics::StatisticsId::kSbSetup
@ kSbSetup
encrypto::motion::RunTimeStatistics::Get
const TimePointPair & Get(StatisticsId id) const
Definition: run_time_statistics.cpp:36
encrypto::motion::RunTimeStatistics::PrintHumanReadable
std::string PrintHumanReadable() const
Definition: run_time_statistics.cpp:45
encrypto::motion::At
static C::value_type At(const C &container, RunTimeStatistics::StatisticsId id)
Definition: analysis.cpp:52
encrypto::motion::RunTimeStatistics::StatisticsId::kMax
@ kMax
encrypto::motion::RunTimeStatistics::StatisticsId::kOtExtensionSetup
@ kOtExtensionSetup
encrypto::motion::ToMilliseconds
static double ToMilliseconds(const RunTimeStatistics::TimePointPair &tpp)
Definition: run_time_statistics.cpp:31
encrypto::motion::RunTimeStatistics::StatisticsId::kSpPresetup
@ kSpPresetup
encrypto::motion::RunTimeStatistics::StatisticsId::kEvaluate
@ kEvaluate
encrypto::motion::RunTimeStatistics::StatisticsId::kMtSetup
@ kMtSetup
encrypto::motion::RunTimeStatistics::StatisticsId::kPreprocessing
@ kPreprocessing
encrypto::motion::RunTimeStatistics::StatisticsId::kGatesOnline
@ kGatesOnline
encrypto::motion::RunTimeStatistics::StatisticsId::kBaseOts
@ kBaseOts
encrypto::motion
Definition: algorithm_description.cpp:35
encrypto::motion::RunTimeStatistics::StatisticsId::kMtPresetup
@ kMtPresetup
encrypto::motion::RunTimeStatistics::TimePoint
std::chrono::time_point< ClockType > TimePoint
Definition: run_time_statistics.h:34
encrypto::motion::RunTimeStatistics
Definition: run_time_statistics.h:32
encrypto::motion::RunTimeStatistics::StatisticsId::kSbPresetup
@ kSbPresetup
encrypto::motion::RunTimeStatistics::StatisticsId::kGatesSetup
@ kGatesSetup
encrypto::motion::RunTimeStatistics::GetTime
TimePoint GetTime()
Definition: run_time_statistics.h:53
encrypto::motion::RunTimeStatistics::StatisticsId
StatisticsId
Definition: run_time_statistics.h:37
encrypto::motion::RunTimeStatistics::data
std::array< TimePointPair, static_cast< std::size_t >StatisticsId::kMax)+1 > data
Definition: run_time_statistics.h:71
run_time_statistics.h
encrypto::motion::RunTimeStatistics::RecordStart
void RecordStart()
Definition: run_time_statistics.h:56
encrypto::motion::RunTimeStatistics::ClockType
std::chrono::steady_clock ClockType
Definition: run_time_statistics.h:33
encrypto::motion::RunTimeStatistics::StatisticsId::kSpSetup
@ kSpSetup