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

Add raw GSL interpolation evaluation to the benchmark

parent af4fcb80
#include <benchmark/benchmark.h>
#include <Map.hpp>
#include <Parser.hpp>
#include <Spline2D.hpp>
#include <gsl/gsl_interp2d.h>
#include <benchmark/benchmark.h>
#include <fstream>
#include <iostream>
#include <random>
......@@ -12,7 +14,7 @@
using namespace noname;
static void BM_Eval(benchmark::State &state) {
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";
......@@ -34,7 +36,7 @@ static void BM_Eval(benchmark::State &state) {
spline.eval(x.back(), y.front());
}
}
BENCHMARK(BM_Eval);
BENCHMARK(BM_EvalSpline2D);
static void BM_EvalMap(benchmark::State &state) {
std::string const prefix = "/scratch/"; // edit this line
......@@ -61,4 +63,36 @@ static void BM_EvalMap(benchmark::State &state) {
}
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 *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_interp_accel_free(yacc);
gsl_interp_accel_free(xacc);
gsl_interp2d_free(spline);
}
BENCHMARK(BM_EvalRawGSL);
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