Timer#
-
class numpy::Timer#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use Timer
Timer obj;
// ... operations ...
Other Methods#
Code Examples#
The following examples are extracted from the test suite.
elapsed_milliseconds (np_test_1_all.cpp:6048)
6038void test_timer_accuracyBenchmarkSorting() {
6039 std::cout << "========= test_timer_accuracy =======================";
6040
6041 Timer timer;
6042 timer.start();
6043
6044 // Sleep for a known duration (10ms)
6045 std::this_thread::sleep_for(std::chrono::milliseconds(10));
6046
6047 double elapsed = timer.elapsed_milliseconds();
6048
6049 // Timer should be approximately 10ms (allow 5ms tolerance for system variance)
6050 if (!(elapsed >= 3.0 && elapsed <= 105.0)) {
6051 std::string description = std::string("test_timer_accuracyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(elapsed >= 3.0 && elapsed <= 105.0)";
6052 std::cout << std::string("[FAIL] ") + description << std::endl;
6053 throw std::runtime_error(description);
6054 }
6055 // std::cout << "Timer accuracy test passed. Elapsed: " << elapsed << " ms" << std::endl;
6056
6057 std::cout << " -> tests passed" << std::endl;
start (np_test_1_all.cpp:6043)
6033 std::cout << " -> tests passed" << std::endl;
6034}
6035
6036// ------ merging np_test_benchmark_sorting.cpp -- number of functions merged= 11 --------------------------------
6037
6038void test_timer_accuracyBenchmarkSorting() {
6039 std::cout << "========= test_timer_accuracy =======================";
6040
6041 Timer timer;
6042 timer.start();
6043
6044 // Sleep for a known duration (10ms)
6045 std::this_thread::sleep_for(std::chrono::milliseconds(10));
6046
6047 double elapsed = timer.elapsed_milliseconds();
6048
6049 // Timer should be approximately 10ms (allow 5ms tolerance for system variance)
6050 if (!(elapsed >= 3.0 && elapsed <= 105.0)) {
6051 std::string description = std::string("test_timer_accuracyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(elapsed >= 3.0 && elapsed <= 105.0)";
6052 std::cout << std::string("[FAIL] ") + description << std::endl;