#include "utils.h"
#include <algorithm>
#include <benchmark/benchmark.h>
#include <cassert>
#include <charconv>
#include <fstream>
#include <ranges>
#include <sstream>
#include <vector>
Go to the source code of this file.
|
| std::string | file_read (const std::string_view file_name) |
| | Open a file a return a string of the contents.
|
| void | BM_split_on_comma (benchmark::State &state) |
| | BENCHMARK (BM_split_on_comma) |
| void | BM_split_on_comma2 (benchmark::State &state) |
| | BENCHMARK (BM_split_on_comma2) |
| std::vector< std::vector< double > > | to_series (const std::string csv) |
| | Open a CSV file and return a vector of floating points for each row.
|
| std::vector< std::vector< double > > | to_series3 (const std::string &csv) |
| | Open a CSV file and return a vector of floating points for each row.
|
| std::vector< std::vector< double > > | to_series4 (const std::string &csv) |
| | Open a CSV file and return a vector of floating points for each row.
|
|
| const auto | split_on_comma |
| | Take a row of data, split on delimiter and return a row of floating points.
|
| const auto | split_on_comma2 |
| | Take a row of data, split on delimiter and return a row of floating points.
|
◆ BENCHMARK() [1/2]
◆ BENCHMARK() [2/2]
◆ BM_split_on_comma()
| void BM_split_on_comma |
( |
benchmark::State & | state | ) |
|
Definition at line 46 of file file.cxx.
46 {
47 auto &&row = std::string{"1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0"};
48 for (auto _ : state) {
50 benchmark::DoNotOptimize(xs);
51 }
52}
const auto split_on_comma
Take a row of data, split on delimiter and return a row of floating points.
const std::vector< std::vector< double > > xs
An example of a full set of price data.
◆ BM_split_on_comma2()
| void BM_split_on_comma2 |
( |
benchmark::State & | state | ) |
|
Definition at line 67 of file file.cxx.
67 {
68 auto &&row = std::string{"1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0"};
69 for (auto _ : state) {
71 benchmark::DoNotOptimize(xs);
72 }
73}
const auto split_on_comma2
Take a row of data, split on delimiter and return a row of floating points.
◆ file_read()
| std::string file_read |
( |
const std::string_view | file_name | ) |
|
Open a file a return a string of the contents.
Open file and return the contents as a string
Definition at line 12 of file file.cxx.
12 {
13
14
15 std::ifstream in{std::string{file_name}};
16
17 if (not in.good())
18 return {};
19
20
21 in.seekg(0, std::ios::end);
22
23
24 std::string out(in.tellg(), '\0');
25
26
27 in.seekg(0, std::ios::beg);
28
29
30 in.read(out.data(), out.size());
31
32 return out;
33}
◆ to_series()
| std::vector< std::vector< double > > to_series |
( |
const std::string | csv | ) |
|
Open a CSV file and return a vector of floating points for each row.
Definition at line 78 of file file.cxx.
78 {
79
80
81 std::istringstream in{csv};
82 std::ranges::istream_view<std::string> rows(in);
83
84
85 return rows | std::views::drop(1) | std::views::transform(
split_on_comma)
86 | std::ranges::to<std::vector<std::vector<double>>>();
87};
◆ to_series3()
| std::vector< std::vector< double > > to_series3 |
( |
const std::string & | csv | ) |
|
Open a CSV file and return a vector of floating points for each row.
Definition at line 90 of file file.cxx.
90 {
91
92
93 std::istringstream in{csv};
94 std::ranges::istream_view<std::string> rows(in);
95
96
97 auto &&px =
99
100
102
103
104 auto &&series = std::vector<std::vector<double>>{};
105
106 for (auto v : px) {
107
108
109 std::ranges::copy(v, std::begin(xs));
110
111
112 series.emplace_back(xs);
113 }
114
115 return std::move(series);
116};
constexpr auto cells
Number of cells in a row of price data.
◆ to_series4()
| std::vector< std::vector< double > > to_series4 |
( |
const std::string & | csv | ) |
|
Open a CSV file and return a vector of floating points for each row.
Definition at line 119 of file file.cxx.
119 {
120
121
122 std::istringstream in{csv};
123 std::ranges::istream_view<std::string> rows(in);
124
125
126 auto &&px =
128
129
130 auto &&series = std::vector<std::vector<double>>{};
131 series.reserve(std::ranges::distance(px));
132
133 std::ranges::transform(px, std::back_inserter(series), [&](auto &&v) {
134
136 std::ranges::copy(v, std::begin(xs));
138 });
139
140 return series;
141};
◆ split_on_comma
| const auto split_on_comma |
Initial value:= [](auto &row) {
using namespace std::views;
return row | split(',') | transform([](auto &&val) -> double {
auto str = std::string{cbegin(val), cend(val)};
double value{};
std::from_chars(str.data(), str.data() + str.size(), value);
return value;
});
}
Take a row of data, split on delimiter and return a row of floating points.
Definition at line 36 of file file.cxx.
36 {
37 using namespace std::views;
38 return row | split(',') | transform([](auto &&val) -> double {
39 auto str = std::string{cbegin(val), cend(val)};
40 double value{};
41 std::from_chars(str.data(), str.data() + str.size(), value);
42 return value;
43 });
44};
◆ split_on_comma2
| const auto split_on_comma2 |
Initial value:= [](auto &&row) {
using namespace std::views;
return row | split(',') | transform([](auto &&val) {
auto &&str = std::string{cbegin(val), cend(val)};
auto value = double{};
std::from_chars(str.data(), str.data() + str.size(), value);
return value;
});
}
Take a row of data, split on delimiter and return a row of floating points.
Definition at line 57 of file file.cxx.
57 {
58 using namespace std::views;
59 return row | split(',') | transform([](auto &&val) {
60 auto &&str = std::string{cbegin(val), cend(val)};
61 auto value = double{};
62 std::from_chars(str.data(), str.data() + str.size(), value);
63 return value;
64 });
65};