#include #include #include #include #include #include #include #include "funcs.hpp" #include "generalAlgorithm.hpp" #include "specialAlgorithm.hpp" #define TIMING_ITERATIONS 5 void timing() { arma::vec sub_diag, main_diag, sup_diag, g_vec; int n_steps; std::ofstream ofile; ofile.open("output/timing.txt"); // Timing for (int i=1; i < N_STEPS_EXP; i++) { n_steps = std::pow(10, i); clock_t g_1, g_2, s_1, s_2; double g_res = 0, s_res = 0; // Repeat a number of times to take an average for (int j=0; j < TIMING_ITERATIONS; j++) { build_arrays(n_steps, sub_diag, main_diag, sup_diag, g_vec); g_1 = clock(); general_algorithm(sub_diag, main_diag, sup_diag, g_vec); g_2 = clock(); g_res += (double) (g_2 - g_1) / CLOCKS_PER_SEC; // Rebuild g_vec for the special alg build_g_vec(n_steps, g_vec); s_1 = clock(); special_algorithm(-1., 2., -1., g_vec); s_2 = clock(); s_res += (double) (s_2 - s_1) / CLOCKS_PER_SEC; } // Write the average time to file ofile << n_steps << "," << g_res / (double) TIMING_ITERATIONS << "," << s_res / (double) TIMING_ITERATIONS << std::endl; } ofile.close(); } int main() { timing(); general_algorithm_main(); general_algorithm_error(); special_algorithm_main(); }