Commit 3762c3d7 authored by Damien L-G's avatar Damien L-G

Add benchmark for eval

parent f8892759
#include <benchmark/benchmark.h>
#include <noname_Map.hpp>
#include <noname_Parser.hpp>
#include <noname_Spline2D.hpp>
#include <fstream>
#include <iostream>
#include <random>
#include <string>
#include <vector>
using namespace noname;
static void BM_Eval(benchmark::State &state) {
std::string const prefix = "/scratch/"; // edit this line
std::string const fx = prefix + "T.csv";
std::string const fy = prefix + "p.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 const tz = transpose_z(x.size(), y.size(), z);
Spline2D<Bicubic> spline(x, y, tz);
// 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) {
// spline.eval(dist_x(gen), dist_y(gen));
spline.eval(x.back(), y.front());
}
}
BENCHMARK(BM_Eval);
static void BM_EvalMap(benchmark::State &state) {
std::string const prefix = "/scratch/"; // edit this line
std::string const fx = prefix + "T.csv";
std::string const fy = prefix + "p.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);
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