NSIS-ka
A free C++ implementation of NSIS protocols

root/natfw-nslp/trunk/eval/benchmark.cpp @ 2274

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 * benchmark.cpp - a class for performing benchmarks
3 *
4 * $Id$
5 * $HeadURL$
6 *
7 */
8#include <iostream>
9#include <ctime>
10
11#include "logfile.h"
12#include "benchmark.h"
13
14
15/*
16 * Protlib logging, needed for linking.
17 */
18protlib::log::logfile commonlog;
19protlib::log::logfile &protlib::log::DefaultLog(commonlog);
20
21
22using namespace natfw;
23
24
25benchmark::benchmark() {
26        using namespace protlib::log;
27
28        /*
29         * Turn off logging.
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 * Run the benchmark.
41 *
42 * This method runs the perform_task() method @a num_times.
43 *
44 * @param name the name of the benchmark
45 * @param num_times the number of times to run perform_task()
46 */
47void 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        // used to decide when to display a progress indicator
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// EOF
Note: See TracBrowser for help on using the browser.