streams.cpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Includes
12 *****************************************************************************/
13 
14 #include <iostream>
15 #include <ecl/threads/priority.hpp>
16 #include <ecl/time/stopwatch.hpp>
17 #include <ecl/streams.hpp>
18 #include <ecl/formatters.hpp>
19 
20 /*****************************************************************************
21 ** Using
22 *****************************************************************************/
23 
25 using ecl::StopWatch;
26 using ecl::TimeStamp;
27 using ecl::Format;
29 
30 /*****************************************************************************
31 ** Main
32 *****************************************************************************/
33 
34 int main() {
35  try {
36  ecl::set_priority(ecl::RealTimePriority4);
37  } catch ( StandardException &e ) {
38  // dont worry about it.
39  }
40 
41  StopWatch stopwatch;
42  TimeStamp times[6];
43  unsigned int lines_to_write = 1;
44  float f = 33.54235235;
45  Format<double> format; format.precision(2); format.width(5);
46 
47  std::cout << std::endl;
48  std::cout << "***********************************************************" << std::endl;
49  std::cout << " Printf" << std::endl;
50  std::cout << "***********************************************************" << std::endl;
51  std::cout << std::endl;
52 
53  for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
54  printf("Heya Dude\n");
55  }
56  stopwatch.restart();
57  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
58  printf("Heya Dude\n");
59  }
60  times[0] = stopwatch.split();
61  for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
62  printf("%4.2f \n",f);
63  }
64  stopwatch.restart();
65  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
66  printf("%4.2f \n",f);
67  }
68  times[3] = stopwatch.split();
69 
70  std::cout << std::endl;
71  std::cout << "***********************************************************" << std::endl;
72  std::cout << " Cout" << std::endl;
73  std::cout << "***********************************************************" << std::endl;
74  std::cout << std::endl;
75 
76  for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
77  std::cout << "Heya Dude\n";
78  }
79  std::cout.flush();
80  stopwatch.restart();
81  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
82  std::cout << "Heya Dude\n";
83  }
84  std::cout.flush();
85  times[1] = stopwatch.split();
86 
87  std::cout.precision(4);
88  for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
89  std::cout << f << " \n";
90  }
91  std::cout.flush();
92  stopwatch.restart();
93  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
94  std::cout << f << " \n";
95  }
96  std::cout.flush();
97  times[4] = stopwatch.split();
98 
99  std::cout << std::endl;
100  std::cout << "***********************************************************" << std::endl;
101  std::cout << " Ostream" << std::endl;
102  std::cout << "***********************************************************" << std::endl;
103  std::cout << std::endl;
104 
105  OConsoleStream ostream;
106  for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
107  ostream << "Heya Dude\n";
108  }
109  ostream.flush();
110  stopwatch.restart();
111  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
112  ostream << "Heya Dude\n";
113  }
114  ostream.flush();
115  times[2] = stopwatch.split();
116 
117  for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
118  ostream << format(f) << " \n";
119  }
120  ostream.flush();
121  stopwatch.restart();
122  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
123  ostream << format(f) << " \n";
124  }
125  ostream.flush();
126  times[5] = stopwatch.split();
127 
128  std::cout << std::endl;
129  std::cout << "***********************************************************" << std::endl;
130  std::cout << " Times" << std::endl;
131  std::cout << "***********************************************************" << std::endl;
132  std::cout << std::endl;
133 
134  std::cout << "Writing Char Strings:" << std::endl;
135  std::cout << " printf : " << times[0].nsec() << " ns" << std::endl;
136  std::cout << " cout : " << times[1].nsec() << " ns" << std::endl;
137  std::cout << " OConsoleStream : " << times[2].nsec() << " ns" << std::endl;
138  std::cout << "Streaming Floats:" << std::endl;
139  std::cout << " printf : " << times[3].nsec() << " ns" << std::endl;
140  std::cout << " cout : " << times[4].nsec() << " ns" << std::endl;
141  std::cout << " OConsoleStream : " << times[5].nsec() << " ns" << std::endl;
142 
143  std::cout << std::endl;
144  std::cout << "***********************************************************" << std::endl;
145  std::cout << " Passed" << std::endl;
146  std::cout << "***********************************************************" << std::endl;
147  std::cout << std::endl;
148 
149  return 0;
150 }
main
int main()
Definition: streams.cpp:34
formatters.hpp
ecl::OConsoleStream
TextStream< OConsole > OConsoleStream
ecl::TextStream
f
void f(int i)
streams.hpp
ecl::StandardException
ecl::Format
stopwatch.hpp
priority.hpp
ecl::RealTimePriority4
RealTimePriority4


ecl_core_apps
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:52