123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #ifndef UTILS__H
- #define UTILS__H
- #include <math.h>
- #include <time.h>
- #include <iostream>
- using namespace std;
- template<class T> T CheckBounds(const T& value, const T& min, const T& max)
- {
- if (value<min) {
- return min;
- }
- if (value>max) {
- 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<uint>(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
|