6#include <benchmark/benchmark.h>
13const std::vector<std::vector<double>>
xs = [] {
14 auto &&
xs = std::vector<std::vector<double>>{};
15 auto &&row = std::vector<double>{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
17 for (
size_t i = 0; i < 2000; ++i) {
18 row[0] =
static_cast<double>(i);
26constexpr auto xs2 = std::array{1, 2, 3, 4, 5, 6};
29constexpr auto xs3 = [] {
30 std::array<double, 2000>
xs;
32 xs[i] =
static_cast<double>(i);
43 benchmark::DoNotOptimize(
44 std::ranges::for_each(xs | slide(
win) | filter(
is_entry), [](
auto) {}));
49 benchmark::DoNotOptimize(std::ranges::for_each(
55 benchmark::DoNotOptimize(
to_exit(xs | take(
win)));
65 benchmark::DoNotOptimize(
to_vwap(xs));
70 benchmark::DoNotOptimize(
to_vwap2(xs));
75 benchmark::DoNotOptimize(
to_atr(xs));
80 benchmark::DoNotOptimize(
to_atr2(xs));
85 benchmark::DoNotOptimize(
to_atr3(xs));
134 benchmark::DoNotOptimize(
to_size(xs));
139 benchmark::DoNotOptimize(
to_first(xs2));
144 benchmark::DoNotOptimize(
to_last(xs2));
149 benchmark::DoNotOptimize(
to_sum(xs3));
154 benchmark::DoNotOptimize(
to_sum2(xs3));
159 benchmark::DoNotOptimize(
to_spot(xs2));
164 benchmark::DoNotOptimize(
identity(xs3));
169 benchmark::DoNotOptimize(
identity2(xs3));
174 benchmark::DoNotOptimize(
to_profit(100.0, 110.0));
193 benchmark::DoNotOptimize(
to_time(xs2));
198 benchmark::DoNotOptimize(
to_open(xs2));
203 benchmark::DoNotOptimize(
to_high(xs2));
208 benchmark::DoNotOptimize(
to_low(xs2));
213 benchmark::DoNotOptimize(
to_close(xs2));
218 benchmark::DoNotOptimize(
to_volume(xs2));
230int main(
int argc,
char **argv) {
231 ::benchmark::Initialize(&argc, argv);
232 ::benchmark::RunSpecifiedBenchmarks();
int main(int argc, char **argv)
constexpr auto xs2
A single row of price data.
constexpr auto xs3
A single column of price data.
const std::vector< std::vector< double > > xs
An example of a full set of price data.
Core routines that don't depend on any other fx routines.
void BM_identity(benchmark::State &state)
constexpr auto to_atr(auto &&series)
Calculate ATR of a series.
constexpr auto to_first(std::ranges::range auto &&xs)
Return the first entry in a series.
void BM_to_spot(benchmark::State &state)
constexpr double to_vwap(std::ranges::range auto &&xs)
Calculate VWAP rolling average.
constexpr auto to_time(std::ranges::range auto &&xs)
Get time of a data point.
void BM_to_exit(benchmark::State &state)
void BM_to_average_volume2(benchmark::State &state)
void BM_to_volume(benchmark::State &state)
constexpr auto to_average_func
auto to_exit2
Find an exit in a series.
constexpr auto to_sum2(std::ranges::range auto &&xs)
Calculate sum of series.
void BM_is_entry2(benchmark::State &state)
constexpr auto to_atr2(auto &&series)
Calculate ATR of a series.
constexpr auto to_last
Return the last entry in a series.
constexpr double to_vwap2(std::ranges::range auto &&xs)
Calculate VWAP rolling average.
constexpr auto to_low(std::ranges::range auto &&xs)
Get low price for a data point.
auto to_exit
Find an exit in a series.
void BM_to_vwap(benchmark::State &state)
void BM_to_close(benchmark::State &state)
constexpr double to_atr3(auto &&series)
Calculate ATR of a series.
constexpr auto to_average_volume
Calculate average volume over a series.
void BM_identity2(benchmark::State &state)
auto is_recent_dip2(auto &&series)
Test if there has been a recent minimum.
void BM_to_sum2(benchmark::State &state)
constexpr auto to_average_func2
void BM_to_exit2(benchmark::State &state)
void BM_to_sum(benchmark::State &state)
constexpr auto win
The number of prices in a trading window.
void BM_to_atr(benchmark::State &state)
void BM_to_time(benchmark::State &state)
void BM_to_average_func(benchmark::State &state)
constexpr auto to_profit(auto &&entry, auto &&exit)
Calculate profit from a trade.
void BM_to_profit(benchmark::State &state)
auto is_entry2
Calculate if the final price is an entry.
void BM_is_entry(benchmark::State &state)
void BM_to_high(benchmark::State &state)
void BM_to_size(benchmark::State &state)
constexpr auto identity2
Just passing through.
void BM_to_atr2(benchmark::State &state)
void BM_to_open(benchmark::State &state)
constexpr auto to_sum(std::ranges::range auto &&xs)
Calculate sum of series.
void BM_to_low(benchmark::State &state)
constexpr auto identity
Just passing through.
void BM_to_average_func2(benchmark::State &state)
void BM_to_vwap2(benchmark::State &state)
void BM_to_average_volume(benchmark::State &state)
constexpr auto to_close(std::ranges::range auto &&xs)
Get close price for a data point.
void BM_is_recent_dip2(benchmark::State &state)
constexpr auto to_open(std::ranges::range auto &&xs)
Get open price for a data point.
constexpr auto to_volume
Get total volume for a data point.
constexpr auto to_spot
Calculate spot value, note we don't average all of the OHLC prices.
void BM_to_first(benchmark::State &state)
constexpr auto to_high(std::ranges::range auto &&xs)
Get high price for a data point.
void BM_to_last(benchmark::State &state)
constexpr T to_size(std::ranges::range auto &&xs)
Calculate size of a series, return type depends on input param.
constexpr auto to_average_volume2
Calculate average volume over a series.
auto is_entry
Calculate if the final price is an entry.
void BM_to_atr3(benchmark::State &state)