Commit ef9f60f7 authored by Damien L-G's avatar Damien L-G

Cleanup benchmark

parent 0d0546ce
......@@ -14,80 +14,42 @@
using namespace noname;
std::string const prefix = "/scratch/"; // edit this line
std::string const fx = prefix + "p.csv";
std::string const fy = prefix + "T.csv";
std::string const fz = prefix + "h.csv";
std::vector<double> extract_from(std::string const &filename,
std::vector<double> (*parse)(std::istream &)) {
std::fstream fs(filename);
return parse(fs);
};
char const sep = '?';
std::string const k = sep + fx + sep + fy + sep + fz + sep;
auto const _x = extract_from(fx, parse_x);
auto const _y = extract_from(fy, parse_y);
auto const _z = extract_from(fz, parse_z);
static void BM_EvalSpline2D(benchmark::State &state) {
std::string const prefix = "/scratch/"; // edit this line
std::string const fx = prefix + "p.csv";
std::string const fy = prefix + "T.csv";
std::string const fz = prefix + "h.csv";
auto extract_from = [](std::string const &filename,
std::vector<double> (*parse)(std::istream &)) {
std::fstream fs(filename);
return parse(fs);
};
auto const x = extract_from(fx, parse_x);
auto const y = extract_from(fy, parse_y);
auto const z = extract_from(fz, parse_z);
Spline2D<Bicubic> spline(x, y, z);
Spline2D<Bicubic> spline(_x, _y, _z);
// std::random_device gen(0);
// std::uniform_real_distribution<double> dist_x(x.front(), x.back());
// std::uniform_real_distribution<double> dist_y(y.front(), y.back());
// std::uniform_real_distribution<double> dist_x(_x.front(), _x.back());
// std::uniform_real_distribution<double> dist_y(_y.front(), _y.back());
for (auto _ : state) {
// spline.eval(dist_x(gen), dist_y(gen));
spline.eval(x.back(), y.front());
spline.eval(_x.back(), _y.front());
}
}
BENCHMARK(BM_EvalSpline2D);
static void BM_EvalMap(benchmark::State &state) {
std::string const prefix = "/scratch/"; // edit this line
std::string const fx = prefix + "p.csv";
std::string const fy = prefix + "T.csv";
std::string const fz = prefix + "h.csv";
auto extract_from = [](std::string const &filename,
std::vector<double> (*parse)(std::istream &)) {
std::fstream fs(filename);
return parse(fs);
};
auto const x = extract_from(fx, parse_x);
auto const y = extract_from(fy, parse_y);
char const sep = '?';
std::string const k = sep + fx + sep + fy + sep + fz + sep;
std::ignore = Map<Spline2D<Bicubic>>::get_spline(k);
// std::random_device gen(0);
// std::uniform_real_distribution<double> dist_x(x.front(), x.back());
// std::uniform_real_distribution<double> dist_y(y.front(), y.back());
for (auto _ : state) {
// Map<Spline2D<Bicubic>>::get_spline(k)->eval(dist_x(gen), dist_y(gen));
Map<Spline2D<Bicubic>>::get_spline(k)->eval(x.back(), y.front());
}
}
BENCHMARK(BM_EvalMap);
static void BM_EvalRawGSL(benchmark::State &state) {
std::string const prefix = "/scratch/"; // edit this line
std::string const fx = prefix + "p.csv";
std::string const fy = prefix + "T.csv";
std::string const fz = prefix + "h.csv";
auto extract_from = [](std::string const &filename,
std::vector<double> (*parse)(std::istream &)) {
std::fstream fs(filename);
return parse(fs);
};
auto const x = extract_from(fx, parse_x);
auto const y = extract_from(fy, parse_y);
auto const z = extract_from(fz, parse_z);
auto *spline = gsl_interp2d_alloc(gsl_interp2d_bicubic, x.size(), y.size());
gsl_interp2d_init(spline, x.data(), y.data(), z.data(), x.size(), y.size());
auto *spline = gsl_interp2d_alloc(gsl_interp2d_bicubic, _x.size(), _y.size());
gsl_interp2d_init(spline, _x.data(), _y.data(), _z.data(), _x.size(),
_y.size());
auto *xacc = gsl_interp_accel_alloc();
auto *yacc = gsl_interp_accel_alloc();
// std::random_device gen(0);
// std::uniform_real_distribution<double> dist_x(x.front(), x.back());
// std::uniform_real_distribution<double> dist_y(y.front(), y.back());
for (auto _ : state) {
// gsl_interp2d_eval(spline, x.data(), y.data(), z.data(), dist_x(gen),
// dist_y(gen), xacc, yacc);
gsl_interp2d_eval(spline, x.data(), y.data(), z.data(), x.back(), y.front(),
xacc, yacc);
gsl_interp2d_eval(spline, _x.data(), _y.data(), _z.data(), _x.back(),
_y.front(), xacc, yacc);
}
gsl_interp_accel_free(yacc);
gsl_interp_accel_free(xacc);
......@@ -95,19 +57,27 @@ static void BM_EvalRawGSL(benchmark::State &state) {
}
BENCHMARK(BM_EvalRawGSL);
int const nx = 200;
int const ny = 200;
std::vector<double> iota_vector(size_t n, double val = 0.) {
std::vector<double> v(n);
std::iota(v.begin(), v.end(), val);
return v;
static void BM_EvalMap(benchmark::State &state) {
Map<Spline2D<Bicubic>>::get_spline(k);
for (auto _ : state) {
Map<Spline2D<Bicubic>>::get_spline(k)->eval(_x.back(), _y.front());
}
}
BENCHMARK(BM_EvalMap);
static void BM_EvalMapGetSplineOnly(benchmark::State &state) {
Map<Spline2D<Bicubic>>::get_spline(k);
for (auto _ : state) {
Map<Spline2D<Bicubic>>::get_spline(k);
}
}
BENCHMARK(BM_EvalMapGetSplineOnly);
static void BM_ConstructSpline2D(benchmark::State &state) {
for (auto _ : state) {
auto const x = iota_vector(nx);
auto const y = iota_vector(ny);
std::vector<double> const z(nx * ny);
auto const x = _x;
auto const y = _y;
auto const z = _z;
Spline2D<Bicubic> spline(x, y, z);
}
}
......@@ -115,19 +85,19 @@ BENCHMARK(BM_ConstructSpline2D);
static void BM_ConstructSpline2DMoveArrays(benchmark::State &state) {
for (auto _ : state) {
auto x = iota_vector(nx);
auto y = iota_vector(ny);
std::vector<double> z(nx * ny);
auto x = _x;
auto y = _y;
auto z = _z;
Spline2D<Bicubic> spline(std::move(x), std::move(y), std::move(z));
}
}
BENCHMARK(BM_ConstructSpline2DMoveArrays);
static void BM_ConstructRawGSL(benchmark::State &state) {
auto const x = iota_vector(nx);
auto const y = iota_vector(ny);
std::vector<double> const z(nx * ny);
for (auto _ : state) {
auto const x = _x;
auto const y = _y;
auto const z = _z;
auto *spline = gsl_interp2d_alloc(gsl_interp2d_bicubic, x.size(), y.size());
gsl_interp2d_init(spline, x.data(), y.data(), z.data(), x.size(), y.size());
gsl_interp2d_free(spline);
......@@ -135,13 +105,13 @@ static void BM_ConstructRawGSL(benchmark::State &state) {
}
BENCHMARK(BM_ConstructRawGSL);
static void BM_ConstructArraysOnly(benchmark::State &state) {
static void BM_ConstructCopyArraysOnly(benchmark::State &state) {
for (auto _ : state) {
auto const x = iota_vector(nx);
auto const y = iota_vector(ny);
std::vector<double> const z(nx * ny);
auto const x = _x;
auto const y = _y;
auto const z = _z;
}
}
BENCHMARK(BM_ConstructArraysOnly);
BENCHMARK(BM_ConstructCopyArraysOnly);
BENCHMARK_MAIN();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment