|
Revision 2274, 1.5 KB
(checked in by stud-matfried, 7 years ago)
|
|
Added an eval subdirectory for benchmarking parts of the natfw implementation.
|
-
Property svn:keywords set to
Id HeadURL
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | #include <iostream> |
|---|
| 9 | #include <ctime> |
|---|
| 10 | |
|---|
| 11 | #include "logfile.h" |
|---|
| 12 | #include "benchmark.h" |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | protlib::log::logfile commonlog; |
|---|
| 19 | protlib::log::logfile &protlib::log::DefaultLog(commonlog); |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | using namespace natfw; |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | benchmark::benchmark() { |
|---|
| 26 | using namespace protlib::log; |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | commonlog.set_filter(ERROR_LOG, LOG_EMERG + 1); |
|---|
| 32 | commonlog.set_filter(WARNING_LOG, LOG_EMERG + 1); |
|---|
| 33 | commonlog.set_filter(EVENT_LOG, LOG_EMERG + 1); |
|---|
| 34 | commonlog.set_filter(INFO_LOG, LOG_EMERG + 1); |
|---|
| 35 | commonlog.set_filter(DEBUG_LOG, LOG_EMERG + 1); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | void benchmark::run(const std::string &name, unsigned long num_times) { |
|---|
| 48 | using std::cout; |
|---|
| 49 | |
|---|
| 50 | cout << "Running benchmark '" << name << "' (" |
|---|
| 51 | << num_times << " iterations) ...\n"; |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | unsigned tasks_per_dot = num_times / 70; |
|---|
| 55 | |
|---|
| 56 | if ( tasks_per_dot == 0 ) |
|---|
| 57 | tasks_per_dot = 1; |
|---|
| 58 | |
|---|
| 59 | time_t start = time(NULL); |
|---|
| 60 | |
|---|
| 61 | cout << "Starting time: " << ctime(&start); |
|---|
| 62 | |
|---|
| 63 | for ( unsigned i = 1; i <= num_times; i++ ) { |
|---|
| 64 | |
|---|
| 65 | perform_task(); |
|---|
| 66 | |
|---|
| 67 | if ( (i % tasks_per_dot) == 0 ) |
|---|
| 68 | cout << '.' << std::flush; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | time_t stop = time(NULL); |
|---|
| 72 | |
|---|
| 73 | cout << "\n"; |
|---|
| 74 | cout << "Ending time: " << ctime(&stop); |
|---|
| 75 | cout << "Time used in seconds: " << stop - start << "\n"; |
|---|
| 76 | cout << "\n"; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | |
|---|