1 /** @file test_runner.h
3 * Utility functions for benchmarking. */
6 * GiNaC Copyright (C) 1999-2023 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef GINAC_CHECK_TEST_RUNNER_H
24 #define GINAC_CHECK_TEST_RUNNER_H
33 template<typename T> static void
34 run_benchmark(T& benchmark,
35 const unsigned ntests = 10,
36 const std::clock_t t_annoying = 15*CLOCKS_PER_SEC,
37 const std::clock_t t_min = CLOCKS_PER_SEC/100)
39 const std::clock_t start(std::clock());
40 std::clock_t elapsed(start);
51 go_on = benchmark.check();
54 elapsed = std::clock() - start;
55 if (elapsed > t_annoying)
57 } while (n <= ntests || elapsed < t_min);
59 benchmark.print_result(t);
62 // By default long-running timings are disabled (to not annoy the user).
63 // If the GINAC_RUN_EXPENSIVE_TIMINGS environment variable is set to "1",
64 // some of them (which are supposed to be relatively fast) will be enabled.
65 // If GINAC_RUN_EXPENSIVE_TIMINGS is set to "2", all timings are enabled.
66 static int run_expensive_timings_p()
70 static const std::string env_name("GINAC_RUN_EXPENSIVE_TIMINGS");
72 char* envvar = std::getenv(env_name.c_str());
73 if (envvar != nullptr) {
74 value = std::atoi(envvar);
75 if (value < 0 || value > 2)
79 std::cerr << "WARNING: "
80 << "long-running timings are ENABLED."
82 << "Unset the \"" << env_name << "\" "
83 << "environment variable skip them."
90 #endif // ndef GINAC_CHECK_TEST_RUNNER_H