feisty meow concerns codebase  2.140
time_running_app.cpp
Go to the documentation of this file.
1 /*
2  * Name : time_running_app
3  * Author : Chris Koeritz
4  * Purpose:
5  *
6  * A simple test of how long it takes to run a fairly heavy application.
7  *
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
14  */
15 
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>
22 #include <loggers/console_logger.h>
23 #include <loggers/file_logger.h>
25 
26 #include <stdio.h>
27 
28 #ifdef __WIN32__
29  #include <io.h>
30 #endif
31 
32 using namespace application;
33 using namespace basis;
34 using namespace loggers;
35 using namespace filesystem;
36 using namespace textual;
37 using namespace timely;
38 
39 #undef BASE_LOG
40 #define BASE_LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
41 #undef LOG
42 #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
43 
44 class time_running_app : public application_shell
45 {
46 public:
47  time_running_app() : application_shell() {}
48  DEFINE_CLASS_NAME("time_running_app");
49  int execute();
50 };
51 
52 int time_running_app::execute()
53 {
54  FUNCDEF("execute");
56 
57  int test_runs = 10000;
58 
59  time_stamp start; // start of test.
60  astring bins = environment::get("$FEISTY_MEOW_BINARIES");
61  astring app = bins + "/example_application";
62  // save real stdout.
63  int real_stdout = dup(1);
64  // dump app's output.
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());
69  if (ret != 0) {
70  // restore real stdout.
71  dup2(real_stdout, 1);
72  LOG(astring("got an error running the app: ") + app);
73  exit(1);
74  }
75  }
76  time_stamp completion_time; // end of test.
77  // restore real stdout.
78  dup2(real_stdout, 1);
79 
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)));
84 
85  return 0;
86 }
87 
88 HOOPLE_MAIN(time_running_app, )
89 
90 #ifdef __BUILD_STATIC_APPLICATION__
91  // static dependencies found by buildor_gen_deps.sh:
92 #endif // __BUILD_STATIC_APPLICATION__
93 
#define dup2
Definition: Xos2defs.h:16
#define dup
Definition: Xos2defs.h:15
The application_shell is a base object for console programs.
a_sprintf is a specialization of astring that provides printf style support.
Definition: astring.h:440
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
Definition: astring.h:113
Represents a point in time relative to the operating system startup time.
Definition: time_stamp.h:38
time_representation value() const
returns the time_stamp in terms of the lower level type.
Definition: time_stamp.h:61
#define SETUP_COMBO_LOGGER
a macro that retasks the program-wide logger as a combo_logger.
Definition: combo_logger.h:49
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:45
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition: hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37
A logger that sends to the console screen using the standard output device.
#include <time.h>
Definition: earth_time.cpp:37
#define LOG(to_print)