Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ca-bench.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
54#ifndef CA_BENCH_H
55#define CA_BENCH_H
56
57#include <chrono>
58#include <cstddef>
59#include <cstdio>
60#include <utility>
61
62namespace Aleph {
63namespace CA {
64
73{
74 using clock_type = std::chrono::steady_clock;
75 using time_point = clock_type::time_point;
76 time_point start_ = clock_type::now();
77
78public:
81 {
82 start_ = clock_type::now();
83 }
84
87 {
88 const auto now = clock_type::now();
89 const std::chrono::duration<double> d = now - start_;
90 return d.count();
91 }
92
95 {
96 return elapsed_seconds() * 1e3;
97 }
98};
99
110template <typename F>
111[[nodiscard]] inline double bench_seconds(F &&f)
112{
113 Bench_Timer t;
114 std::forward<F>(f)();
115 return t.elapsed_seconds();
116}
117
126[[nodiscard]] inline const char *format_throughput(double cells_per_second)
127{
128 thread_local char buf[64];
130 abs_rate >= 1e9)
131 std::snprintf(buf, sizeof(buf), "%6.2f G cells/s", cells_per_second / 1e9);
132 else if (abs_rate >= 1e6)
133 std::snprintf(buf, sizeof(buf), "%6.2f M cells/s", cells_per_second / 1e6);
134 else if (abs_rate >= 1e3)
135 std::snprintf(buf, sizeof(buf), "%6.2f K cells/s", cells_per_second / 1e3);
136 else
137 std::snprintf(buf, sizeof(buf), "%6.2f cells/s", cells_per_second);
138 return buf;
139}
140
141} // namespace CA
142} // namespace Aleph
143
144#endif // CA_BENCH_H
Tiny start/stop wall-clock timer.
Definition ca-bench.H:73
double elapsed_seconds() const noexcept
Definition ca-bench.H:86
void restart() noexcept
Restart the timer to now().
Definition ca-bench.H:80
clock_type::time_point time_point
Definition ca-bench.H:75
double elapsed_milliseconds() const noexcept
Definition ca-bench.H:94
std::chrono::steady_clock clock_type
Definition ca-bench.H:74
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
const char * format_throughput(double cells_per_second)
Format a "cells per second" rate as "X.XX M cells/s".
Definition ca-bench.H:126
double bench_seconds(F &&f)
Run f() once and return the wall-clock time it took, in seconds.
Definition ca-bench.H:111
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89