-
Notifications
You must be signed in to change notification settings - Fork 543
/
Copy pathscore_recorder.hpp
88 lines (74 loc) · 2.34 KB
/
score_recorder.hpp
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
// Copyright 2009-present MongoDB, Inc.
//
// 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.
#pragma once
#include <chrono>
#include <ctime>
#include <vector>
namespace benchmark {
class score_recorder {
public:
score_recorder() = delete;
score_recorder(double task_size);
//
// Starts the timer for a single iteration (sample) of the benchmark.
//
void start_sample();
//
// Stops the timer and stores the time of the previous sample.
//
// @note
// This method should only be run once after a call to start_sample().
//
void end_sample();
//
// Returns the cumulative wall clock execution time of all samples that have been run.
//
// @return
// The cumulative execution time.
//
std::chrono::milliseconds const& get_execution_time() const;
//
// Gets the nth percentile sample runtime.
//
// @return
// The "nth" percentile recorded sample time.
//
// @exception
// A runtime error is thrown if this method is called before any samples have been recorded.
//
// @note
// This method should only be called after all samples are completed.
//
std::chrono::milliseconds const& get_percentile(unsigned long n);
//
// Gets the score for this benchmark.
//
// @return
// The score for this benchmark in MB/s.
//
// @exception
// A runtime error is thrown if this method is called before any samples have been recorded.
//
// @note
// This method should only be called after all samples are completed.
//
double get_score();
private:
std::chrono::time_point<std::chrono::high_resolution_clock> _last_start;
std::chrono::milliseconds _execution_time;
bool _sorted;
double _task_size;
std::vector<std::chrono::milliseconds> _samples;
};
} // namespace benchmark