#ifndef UTILS__H #define UTILS__H #include #include #include using namespace std; template T CheckBounds(const T& value, const T& min, const T& max) { if (valuemax) { return max; } return value; }; /** Teilt die Zahl num auf in zwei möglichst ähnlich große Faktoren * * @param num * @return gibt einen der beiden Faktoren zurück */ inline uint SplitNumber(const uint& num) { uint factor = static_cast(floor(sqrt(num))); while (factor>1) { if ((num%factor)==0) { return factor; } else { --factor; } } return factor; } ////////////// /** @brief StopWatch provides a simple means for performance tests * usage: * @code StopWatch s; DoSomething(); s.stop(); s.print(); @endcode * * @author Frank Michler * @date 28.10.2009 */ class StopWatch { public: StopWatch() {cpu_start= clock();}; void restart() {cpu_start= clock();}; void stop() {cpu_end=clock();cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;} void print() {cout << "\n\n***********CpuTimeUsed= " << cpu_time_used << " seconds \n";} private: clock_t cpu_start, cpu_end; double cpu_time_used; }; #endif // #ifndef UTILS__H