2018-07-24 22:57:15 +08:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "../src/check.h"
|
|
|
|
#include "benchmark/benchmark.h"
|
|
|
|
#include "output_test.h"
|
|
|
|
|
|
|
|
class TestMemoryManager : public benchmark::MemoryManager {
|
2023-01-10 01:52:18 +08:00
|
|
|
void Start() override {}
|
|
|
|
void Stop(Result& result) override {
|
2022-11-11 23:12:12 +08:00
|
|
|
result.num_allocs = 42;
|
|
|
|
result.max_bytes_used = 42000;
|
2018-07-24 22:57:15 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void BM_empty(benchmark::State& state) {
|
|
|
|
for (auto _ : state) {
|
2023-03-06 22:47:54 +08:00
|
|
|
auto iterations = state.iterations();
|
|
|
|
benchmark::DoNotOptimize(iterations);
|
2018-07-24 22:57:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK(BM_empty);
|
|
|
|
|
|
|
|
ADD_CASES(TC_ConsoleOut, {{"^BM_empty %console_report$"}});
|
|
|
|
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_empty\",$"},
|
2021-06-02 23:06:45 +08:00
|
|
|
{"\"family_index\": 0,$", MR_Next},
|
2021-06-03 04:45:41 +08:00
|
|
|
{"\"per_family_instance_index\": 0,$", MR_Next},
|
Track two more details about runs - the aggregate name, and run name. (#675)
This is related to @BaaMeow's work in https://github.com/google/benchmark/pull/616 but is not based on it.
Two new fields are tracked, and dumped into JSON:
* If the run is an aggregate, the aggregate's name is stored.
It can be RMS, BigO, mean, median, stddev, or any custom stat name.
* The aggregate-name-less run name is additionally stored.
I.e. not some name of the benchmark function, but the actual
name, but without the 'aggregate name' suffix.
This way one can group/filter all the runs,
and filter by the particular aggregate type.
I *might* need this for further tooling improvement.
Or maybe not.
But this is certainly worthwhile for custom tooling.
2018-09-13 20:08:15 +08:00
|
|
|
{"\"run_name\": \"BM_empty\",$", MR_Next},
|
Track 'type' of the run - is it an actual measurement, or an aggregate. (#658)
This is *only* exposed in the JSON. Not in CSV, which is deprecated.
This *only* supposed to track these two states.
An additional field could later track which aggregate this is,
specifically (statistic name, rms, bigo, ...)
The motivation is that we already have ReportAggregatesOnly,
but it affects the entire reports, both the display,
and the reporters (json files), which isn't ideal.
It would be very useful to have a 'display aggregates only' option,
both in the library's console reporter, and the python tooling,
This will be especially needed for the 'store separate iterations'.
2018-08-28 23:11:36 +08:00
|
|
|
{"\"run_type\": \"iteration\",$", MR_Next},
|
2021-06-02 17:34:00 +08:00
|
|
|
{"\"repetitions\": 1,$", MR_Next},
|
2019-03-26 17:53:07 +08:00
|
|
|
{"\"repetition_index\": 0,$", MR_Next},
|
|
|
|
{"\"threads\": 1,$", MR_Next},
|
2018-07-24 22:57:15 +08:00
|
|
|
{"\"iterations\": %int,$", MR_Next},
|
|
|
|
{"\"real_time\": %float,$", MR_Next},
|
|
|
|
{"\"cpu_time\": %float,$", MR_Next},
|
|
|
|
{"\"time_unit\": \"ns\",$", MR_Next},
|
|
|
|
{"\"allocs_per_iter\": %float,$", MR_Next},
|
|
|
|
{"\"max_bytes_used\": 42000$", MR_Next},
|
|
|
|
{"}", MR_Next}});
|
|
|
|
ADD_CASES(TC_CSVOut, {{"^\"BM_empty\",%csv_report$"}});
|
|
|
|
|
2019-03-26 17:53:07 +08:00
|
|
|
int main(int argc, char* argv[]) {
|
2018-07-24 22:57:15 +08:00
|
|
|
std::unique_ptr<benchmark::MemoryManager> mm(new TestMemoryManager());
|
|
|
|
|
|
|
|
benchmark::RegisterMemoryManager(mm.get());
|
|
|
|
RunOutputTests(argc, argv);
|
|
|
|
benchmark::RegisterMemoryManager(nullptr);
|
|
|
|
}
|