diff --git a/benchmark/bm_adim_system.cpp b/benchmark/bm_adim_system.cpp index c90d039..0b397c6 100644 --- a/benchmark/bm_adim_system.cpp +++ b/benchmark/bm_adim_system.cpp @@ -1,491 +1,491 @@ #include #include "specmicp/adimensional/adimensional_system.hpp" #include "specmicp_database/database.hpp" #include "specmicp_common/physics/laws.hpp" #include "specmicp_common/micpsolver/micpsolver.hpp" #include "specmicp/adimensional/adimensional_system_solver.hpp" #include "specmicp/adimensional/adimensional_system_solution.hpp" #include using namespace specmicp; static specmicp::RawDatabasePtr get_simple_database() { specmicp::database::Database thedatabase(TEST_CEMDATA_PATH); std::map swapping ({ {"H[+]","HO[-]"}, }); thedatabase.swap_components(swapping); std::vector to_keep = {"HO[-]", "Ca[2+]"}; thedatabase.keep_only_components(to_keep); thedatabase.remove_half_cell_reactions(std::vector({"H2O", "HO[-]"})); return thedatabase.get_database(); } static AdimensionalSystemConstraints get_simple_constraints(RawDatabasePtr raw_data) { Vector total_concentration = Vector::Zero(raw_data->nb_component()); total_concentration(raw_data->get_id_component("H2O")) = 55.5; total_concentration(raw_data->get_id_component("HO[-]")) = 2e-3; total_concentration(raw_data->get_id_component("Ca[2+]")) = 1e-3; return AdimensionalSystemConstraints(total_concentration); } static void bm_simple_init(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); while(state.KeepRunning()) { AdimensionalSystem system(raw_data, constraints); } } BENCHMARK(bm_simple_init); static void bm_simple_secondary_variables(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { system.set_secondary_variables(x); } } static void bm_ideq_w(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); while(state.KeepRunning()) { index_t id = system.ideq_w(); benchmark::DoNotOptimize(id); } } //BENCHMARK(bm_ideq_w); static void bm_ideq_comp(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); while(state.KeepRunning()) { index_t id = system.ideq_paq(2); benchmark::DoNotOptimize(id); } } //BENCHMARK(bm_ideq_comp); BENCHMARK(bm_simple_secondary_variables); static void bm_simple_secondary_concentration(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { system.set_secondary_concentration(x); } } BENCHMARK(bm_simple_secondary_concentration); static void bm_simple_log_gamma(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_concentration(x); while(state.KeepRunning()) { system.compute_log_gamma(x); } } BENCHMARK(bm_simple_log_gamma); static void bm_debye_huckel(benchmark::State& state) { scalar_t sqrtI = 0.1; scalar_t zi = 2; scalar_t ao = 3.0; while(state.KeepRunning()) { scalar_t a = laws::debye_huckel(sqrtI, zi, ao); benchmark::DoNotOptimize(a); } } BENCHMARK(bm_debye_huckel); static void bm_extended_debye_huckel(benchmark::State& state) { scalar_t ionic_strength = 0.01; scalar_t sqrtI = 0.1; scalar_t zi = 2; scalar_t ao = 3.0; scalar_t bdot = 0.1; while(state.KeepRunning()) { scalar_t a = laws::extended_debye_huckel(ionic_strength, sqrtI, zi, ao, bdot); benchmark::DoNotOptimize(a); } } BENCHMARK(bm_extended_debye_huckel); static void bm_simple_residual_water(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { system.residual_water_conservation(x); } } BENCHMARK(bm_simple_residual_water); static void bm_simple_residual_ca(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { system.residual_component(x, 2); } } BENCHMARK(bm_simple_residual_ca); static void bm_residuals(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { Vector residuals(system.total_variables()); system.get_residuals(x, residuals); } } BENCHMARK(bm_residuals); static void bm_analytical_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { index_t neq = system.total_variables(); Matrix jacobian(neq, neq); system.analytical_jacobian(x, jacobian); } } BENCHMARK(bm_analytical_jacobian); static void bm_finite_difference_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { index_t neq = system.total_variables(); Matrix jacobian(neq, neq); system.finite_difference_jacobian(x, jacobian); } } BENCHMARK(bm_finite_difference_jacobian); static void bm_adim_solver_init(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); while(state.KeepRunning()) { micpsolver::MiCPSolver solver(system); } } BENCHMARK(bm_adim_solver_init); static void bm_adim_solver_residuals(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { Vector residuals(solver.get_neq()); solver.base::compute_residuals(x, residuals); } } BENCHMARK(bm_adim_solver_residuals); static void bm_adim_reformulate_residuals(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { Vector residuals(solver.get_neq()); solver.base::compute_residuals(x, residuals); Vector residuals_reformulated(solver.get_neq()); solver.reformulate_residuals(x, residuals, residuals_reformulated); } } BENCHMARK(bm_adim_reformulate_residuals); static void bm_adim_reformulate_residuals_inplace(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { Vector residuals(solver.get_neq()); solver.base::compute_residuals(x, residuals); solver.reformulate_residuals_inplace(x, residuals); } } BENCHMARK(bm_adim_reformulate_residuals_inplace); static void bm_adim_solver_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { solver.compute_jacobian(x); } } BENCHMARK(bm_adim_solver_jacobian); static void bm_adim_solver_reformulate_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { solver.compute_jacobian(x); solver.reformulate_jacobian(x); } } BENCHMARK(bm_adim_solver_reformulate_jacobian); static void bm_adim_solver_setup_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { solver.setup_jacobian(x); } } BENCHMARK(bm_adim_solver_setup_jacobian); static void bm_adim_solver_scaling_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; index_t neq = solver.get_neq(); Vector residuals(neq); solver.base::compute_residuals(x, residuals); solver.reformulate_residuals_inplace(x, residuals); Matrix jacobian(neq,neq); jacobian.setZero(); system->get_jacobian(x, jacobian); solver.reformulate_jacobian_cck(x, residuals, jacobian); while(state.KeepRunning()) { Vector rscaler(neq), cscaler(neq); solver.scaling_jacobian(jacobian, residuals, rscaler, cscaler); } } BENCHMARK(bm_adim_solver_scaling_jacobian); static void bm_adim_solver_search_direction(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; solver.setup_residuals(x); solver.setup_jacobian(x); Vector update(solver.get_neq()); while(state.KeepRunning()) { solver.search_direction_calculation_no_scaling(update); } } BENCHMARK(bm_adim_solver_search_direction); static void bm_adim_solver_search_direction_scaling(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; solver.setup_residuals(x); solver.setup_jacobian(x); Vector update(solver.get_neq()); while(state.KeepRunning()) { solver.search_direction_calculation(update); } } BENCHMARK(bm_adim_solver_search_direction_scaling); static void bm_adim_system_solver_init(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); while(state.KeepRunning()) { AdimensionalSystemSolver solver(raw_data, constraints); } } BENCHMARK(bm_adim_system_solver_init); static void bm_adim_system_solver_initialize_variables(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystemSolver solver(raw_data, constraints); Vector x; while(state.KeepRunning()) { solver.initialize_variables(x, 0.5, -4); } } BENCHMARK(bm_adim_system_solver_initialize_variables); static void bm_adim_system_solver_solve(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystemSolver solver(raw_data, constraints); while(state.KeepRunning()) { Vector x; solver.initialize_variables(x, 0.5, -4); solver.solve(x, false); benchmark::DoNotOptimize(x); } } BENCHMARK(bm_adim_system_solver_solve); static void bm_adim_system_solver_get_solution(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystemSolver solver(raw_data, constraints); Vector x; solver.solve(x, true); while(state.KeepRunning()) { auto sol = solver.get_raw_solution(x); benchmark::DoNotOptimize(sol); } } BENCHMARK(bm_adim_system_solver_get_solution); static void bm_adim_system_solver_unsafe_get_solution(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystemSolver solver(raw_data, constraints); Vector x; solver.solve(x, true); while(state.KeepRunning()) { auto sol = solver.unsafe_get_raw_solution(x); benchmark::DoNotOptimize(sol); } } BENCHMARK(bm_adim_system_solver_unsafe_get_solution); -BENCHMARK_MAIN() +BENCHMARK_MAIN(); diff --git a/benchmark/bm_common.cpp b/benchmark/bm_common.cpp index f8317e7..c383899 100644 --- a/benchmark/bm_common.cpp +++ b/benchmark/bm_common.cpp @@ -1,89 +1,89 @@ // this file is a micro-benchmark of the specmicp common libs // It uses the google/benchmark framework #include #include "specmicp_common/range_iterator.hpp" #include "specmicp_common/timer.hpp" #include "specmicp_common/moving_average.hpp" using namespace specmicp; // Range iterator // ============== static void BMSimpleLoop(benchmark::State& state) { while (state.KeepRunning()) { for (int i=0; i<100; ++i) { benchmark::DoNotOptimize(i); } } } BENCHMARK(BMSimpleLoop); static void BMRangeIterator(benchmark::State& state) { while (state.KeepRunning()) { for (auto it: RangeIterator(100)) { benchmark::DoNotOptimize(it); } } } BENCHMARK(BMRangeIterator); // Timer // ===== static void BMTimer(benchmark::State& state) { while (state.KeepRunning()) { Timer timer; timer.stop(); } } BENCHMARK(BMTimer); static void BMTimer_restart(benchmark::State& state) { while (state.KeepRunning()) { Timer timer; timer.start(); timer.stop(); } } BENCHMARK(BMTimer_restart); static void BMTimer_elapsedtime(benchmark::State& state) { while (state.KeepRunning()) { Timer timer; timer.stop(); scalar_t x; benchmark::DoNotOptimize(x = timer.elapsed_time()); } } BENCHMARK(BMTimer_elapsedtime); // Moving Average // ============== static void BMMovingAverage_init(benchmark::State& state) { while (state.KeepRunning()) { utils::ExponentialMovingAverage average(0.2, 1.0); benchmark::DoNotOptimize(average); } } BENCHMARK(BMMovingAverage_init); static void BMMovingAverage_addpoint(benchmark::State& state) { while (state.KeepRunning()) { utils::ExponentialMovingAverage average(0.2, 1.0); scalar_t x; benchmark::DoNotOptimize(x = average.add_point(2.0)); } } BENCHMARK(BMMovingAverage_addpoint); -BENCHMARK_MAIN() +BENCHMARK_MAIN(); diff --git a/benchmark/bm_database.cpp b/benchmark/bm_database.cpp index 3624987..b3c7aae 100644 --- a/benchmark/bm_database.cpp +++ b/benchmark/bm_database.cpp @@ -1,235 +1,235 @@ // this file is a micro-benchmark of the database // // right now, this is mainly a test of the data_container. // It uses the google/benchmark framework #include #include "specmicp_database/database.hpp" using namespace specmicp; static database::RawDatabasePtr get_database() { database::Database the_database(TEST_CEMDATA_PATH); return the_database.get_database(); } static void read_nb_components(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); scalar_t x = 0.0; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->nb_component()); } } BENCHMARK(read_nb_components); static void loop_range_components(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); while (state.KeepRunning()) { for (auto i: the_db->range_component()) { benchmark::DoNotOptimize(i); } } } BENCHMARK(loop_range_components); static void loop_standard_components(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); while (state.KeepRunning()) { for (index_t i=0; inb_component();++i) { benchmark::DoNotOptimize(i); } } } BENCHMARK(loop_standard_components); static void loop_range_aqueous(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); while (state.KeepRunning()) { for (auto i: the_db->range_aqueous()) { benchmark::DoNotOptimize(i); } } } BENCHMARK(loop_range_aqueous); static void loop_standard_aqueous(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); while (state.KeepRunning()) { for (index_t i=0; inb_aqueous();++i) { benchmark::DoNotOptimize(i); } } } BENCHMARK(loop_standard_aqueous); static void read_logk_aqueous(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); index_t aqueous = 3; scalar_t x = 0.0; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->logk_aqueous(aqueous)); } } BENCHMARK(read_logk_aqueous); static void read_nuji_aqueous(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); index_t aqueous = 3; index_t component = 3; scalar_t x = 0.0; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->nu_aqueous(aqueous, component)); } } BENCHMARK(read_nuji_aqueous); static void get_id_component_h2o(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); scalar_t id; while (state.KeepRunning()) { benchmark::DoNotOptimize(id = the_db->get_id_component("H2O")); } } BENCHMARK(get_id_component_h2o); static void get_id_component_mg(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); scalar_t id; while (state.KeepRunning()) { benchmark::DoNotOptimize(id = the_db->get_id_component("Mg[2+]")); } } BENCHMARK(get_id_component_mg); static void get_id_component_mg_from_element(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); scalar_t id; while (state.KeepRunning()) { benchmark::DoNotOptimize(id = the_db->get_id_component_from_element("Mg")); } } BENCHMARK(get_id_component_mg_from_element); static void get_label_component_0(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); std::string label; while (state.KeepRunning()) { label = the_db->get_label_component(0); benchmark::DoNotOptimize(label); } } BENCHMARK(get_label_component_0); static void get_label_component_5(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); std::string label; while (state.KeepRunning()) { label = the_db->get_label_component(5); benchmark::DoNotOptimize(label); } } BENCHMARK(get_label_component_5); static void molar_mass_basis_si_direct_scaling(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); scalar_t x; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->molar_mass_basis(2)); } } BENCHMARK(molar_mass_basis_si_direct_scaling); static void molar_mass_basis_si_scaling(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); scalar_t x; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->molar_mass_basis(2, units::SI_units)); } } BENCHMARK(molar_mass_basis_si_scaling); static void molar_mass_basis_no_scaling(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); scalar_t x; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->molar_mass_basis(2, units::CMG_units)); } } BENCHMARK(molar_mass_basis_no_scaling); static void scaling_molar_volume_m(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); scalar_t x; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->scaling_molar_volume(units::SI_units)); } } BENCHMARK(scaling_molar_volume_m); static void scaling_molar_volume_dm(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); scalar_t x; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->scaling_molar_volume(units::CMG_units)); } } BENCHMARK(scaling_molar_volume_dm); static void is_valid(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); the_db->freeze_db(); bool x; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->is_valid()); } } BENCHMARK(is_valid); static void is_valid_nofreeze(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); bool x; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->is_valid()); } } BENCHMARK(is_valid_nofreeze); static void get_hash(benchmark::State& state) { database::RawDatabasePtr the_db = get_database(); size_t x; while (state.KeepRunning()) { benchmark::DoNotOptimize(x = the_db->get_hash()); } } BENCHMARK(get_hash); -BENCHMARK_MAIN() +BENCHMARK_MAIN(); diff --git a/benchmark/bm_logging.cpp b/benchmark/bm_logging.cpp index e6aee1f..a5e927e 100644 --- a/benchmark/bm_logging.cpp +++ b/benchmark/bm_logging.cpp @@ -1,67 +1,67 @@ // this file is a micro-benchmark of the logging capacity // // right now, this is mainly a test of the data_container. // It uses the google/benchmark framework #include #include "specmicp_common/log.hpp" #include #include using namespace specmicp; static void InitLogger(benchmark::State& state) { while (state.KeepRunning()) { std::ofstream stream("/dev/null"); specmicp::init_logger(&stream, specmicp::logger::Info); } } BENCHMARK(InitLogger); static void DebugMessage(benchmark::State& state) { std::ofstream stream("/dev/null"); specmicp::init_logger(&stream, specmicp::logger::Info); while (state.KeepRunning()) { DEBUG << "debug message"; } } // Register the function as a benchmark BENCHMARK(DebugMessage); static void DisregardedWarningMessage(benchmark::State& state) { std::ofstream stream("/dev/null"); specmicp::init_logger(&stream, specmicp::logger::Error); while (state.KeepRunning()) { WARNING << "warning message"; } } // Register the function as a benchmark BENCHMARK(DisregardedWarningMessage); static void WarningMessage(benchmark::State& state) { std::ofstream stream("/dev/null"); specmicp::init_logger(&stream, specmicp::logger::Info); while (state.KeepRunning()) { WARNING << "warning message"; } } // Register the function as a benchmark BENCHMARK(WarningMessage); static void ErrorMessage(benchmark::State& state) { std::ofstream stream("/dev/null"); specmicp::init_logger(&stream, specmicp::logger::Info); while (state.KeepRunning()) { WARNING << "error message"; } } // Register the function as a benchmark BENCHMARK(ErrorMessage); -BENCHMARK_MAIN() +BENCHMARK_MAIN(); diff --git a/benchmark/bm_maths.cpp b/benchmark/bm_maths.cpp index 4253ac3..30aacdc 100644 --- a/benchmark/bm_maths.cpp +++ b/benchmark/bm_maths.cpp @@ -1,292 +1,292 @@ // this file is a micro-benchmark of the maths functions // // It uses the google/benchmark framework #include #include "specmicp_common/types.hpp" #include "specmicp_common/eigen/incl_eigen_core.hpp" #include #include #include "specmicp_common/eigen/incl_eigen_sparse_core.hpp" #include #include #include #include static void pow_to_2(benchmark::State& state) { const int size {10}; Eigen::VectorXd x = Eigen::VectorXd::Random(size); while (state.KeepRunning()) { for (int i=0; i; using SparseT = Eigen::SparseMatrix; static std::vector get_triplets_list() { const int size = 50; std::vector list_triplets; list_triplets.reserve(3*size); list_triplets.push_back(T(0, 0, 20)); list_triplets.push_back(T(0, 1, -10)); for (int i=1; i> solver; solver.compute(mat); Eigen::VectorXd sol = solver.solve(x); } } BENCHMARK(solve_sparse_lu); static void solve_sparse_qr(benchmark::State &state) { SparseT mat(50, 50); auto list_triplets = get_triplets_list(); mat.setFromTriplets(list_triplets.begin(), list_triplets.end()); while(state.KeepRunning()) { Eigen::VectorXd x = Eigen::VectorXd::Random(50); Eigen::SparseQR> solver; solver.compute(mat); Eigen::VectorXd sol = solver.solve(x); } } BENCHMARK(solve_sparse_qr); -BENCHMARK_MAIN() +BENCHMARK_MAIN(); diff --git a/benchmark/bm_mesh.cpp b/benchmark/bm_mesh.cpp index 2fa4243..d0ecec2 100644 --- a/benchmark/bm_mesh.cpp +++ b/benchmark/bm_mesh.cpp @@ -1,114 +1,114 @@ // this file is a micro-benchmark of the maths functions // // It uses the google/benchmark framework #include #include "specmicp_common/types.hpp" #include "dfpm/mesh.hpp" static void uniform_mesh_creation(benchmark::State& state) { while (state.KeepRunning()) { auto the_mesh = specmicp::mesh::uniform_mesh1d({0.1, 50, 5.0}); } } BENCHMARK(uniform_mesh_creation); static void ramp_mesh_creation(benchmark::State& state) { while (state.KeepRunning()) { specmicp::mesh::Ramp1DMeshGeometry ramp_mesh_geom; ramp_mesh_geom.dx_min = 0.05; ramp_mesh_geom.dx_max = 0.5; ramp_mesh_geom.length_ramp = 2; ramp_mesh_geom.length_plateau = 10; ramp_mesh_geom.section = 5; auto the_mesh = specmicp::mesh::ramp_mesh1d(ramp_mesh_geom); } } BENCHMARK(ramp_mesh_creation); static void nb_nodes_50(benchmark::State& state) { auto the_mesh = specmicp::mesh::uniform_mesh1d({0.1, 50, 5.0}); while (state.KeepRunning()) { for (int i=0; i<50; ++i) { auto n = the_mesh->nb_nodes(); benchmark::DoNotOptimize(n); } } } BENCHMARK(nb_nodes_50); static void nb_elements_50(benchmark::State& state) { auto the_mesh = specmicp::mesh::uniform_mesh1d({0.1, 50, 5.0}); while (state.KeepRunning()) { for (int i=0; i<50; ++i) { auto n = the_mesh->nb_elements(); benchmark::DoNotOptimize(n); } } } BENCHMARK(nb_elements_50); static void get_position_50(benchmark::State& state) { auto the_mesh = specmicp::mesh::uniform_mesh1d({0.1, 50, 5.0}); while (state.KeepRunning()) { for (int i=0; i<50; ++i) { auto x = the_mesh->get_position(i); benchmark::DoNotOptimize(x); } } } BENCHMARK(get_position_50); static void get_dx_50(benchmark::State& state) { auto the_mesh = specmicp::mesh::uniform_mesh1d({0.1, 50, 5.0}); while (state.KeepRunning()) { for (auto n: the_mesh->range_nodes()) { auto x = the_mesh->get_dx(n); benchmark::DoNotOptimize(x); } } } BENCHMARK(get_dx_50); static void get_volume_cell_element_50(benchmark::State& state) { auto the_mesh = specmicp::mesh::uniform_mesh1d({0.1, 50, 5.0}); while (state.KeepRunning()) { for (auto n: the_mesh->range_elements()) { auto x = the_mesh->get_volume_cell_element(n, 0); benchmark::DoNotOptimize(x); } } } BENCHMARK(get_volume_cell_element_50); static void get_volume_element_50(benchmark::State& state) { auto the_mesh = specmicp::mesh::uniform_mesh1d({0.1, 50, 5.0}); while (state.KeepRunning()) { for (auto n:the_mesh->range_elements()) { auto x = the_mesh->get_volume_element(n); benchmark::DoNotOptimize(x); } } } BENCHMARK(get_volume_element_50); -BENCHMARK_MAIN() +BENCHMARK_MAIN();