2 * Name : time_running_app
3 * Author : Chris Koeritz
6 * A simple test of how long it takes to run a fairly heavy application.
8 * Copyright (c) 2003-$now By Author. This program is free software; you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either version 2 of
11 * the License or (at your option) any later version. This is online at:
12 * http://www.fsf.org/copyleft/gpl.html
13 * Please send any updates to: fred@gruntose.com
16 #include <basis/astring.h>
17 #include <basis/environment.cpp>
18 #include <basis/functions.h>
19 #include <structures/set.h>
20 #include <timely/time_stamp.h>
21 #include <application/hoople_main.h>
22 #include <loggers/console_logger.h>
23 #include <loggers/file_logger.h>
24 #include <structures/static_memory_gremlin.h>
32 using namespace application;
33 using namespace basis;
34 using namespace loggers;
35 using namespace filesystem;
36 using namespace textual;
37 using namespace timely;
40 #define BASE_LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
42 #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
44 class time_running_app : public application_shell
47 time_running_app() : application_shell() {}
48 DEFINE_CLASS_NAME("time_running_app");
52 int time_running_app::execute()
57 int test_runs = 10000;
59 time_stamp start; // start of test.
60 astring bins = environment::get("$FEISTY_MEOW_BINARIES");
61 astring app = bins + "/example_application";
63 int real_stdout = dup(1);
65 freopen("/dev/null", "w", stdout);
66 for (int i = 0; i < test_runs; i++) {
67 // run the app; sorry about the relative path; change to this dir first.
68 int ret = system(app.s());
70 // restore real stdout.
72 LOG(astring("got an error running the app: ") + app);
76 time_stamp completion_time; // end of test.
77 // restore real stdout.
80 double durat = completion_time.value() - start.value();
81 double secs = durat / 1000.0; // convert to seconds.
82 LOG(a_sprintf("test run took %0.2f milliseconds or %0.2f seconds or %0.2f minutes.", durat, secs, secs / 60.0));
83 LOG(a_sprintf("individual call takes %0.0f milliseconds.", durat / double(test_runs)));
88 HOOPLE_MAIN(time_running_app, )
90 #ifdef __BUILD_STATIC_APPLICATION__
91 // static dependencies found by buildor_gen_deps.sh:
92 #endif // __BUILD_STATIC_APPLICATION__