files.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <iostream>
14 #include <fstream>
15 #include <ecl/threads/priority.hpp>
16 #include <ecl/time/stopwatch.hpp>
17 #include <ecl/devices/ofile.hpp>
21 
22 /*****************************************************************************
23 ** Using
24 *****************************************************************************/
25 
26 using ecl::Append;
27 using ecl::New;
28 using ecl::OFile;
29 using ecl::SharedFile;
30 using ecl::LogStream;
31 using ecl::TextStream;
33 using ecl::StopWatch;
34 using ecl::TimeStamp;
35 
36 /*****************************************************************************
37 ** Enums
38 *****************************************************************************/
39 
40 enum LogMode {
41  Warning,
42  Error
43 };
44 
45 /*****************************************************************************
46 ** Main
47 *****************************************************************************/
48 
49 int main() {
50  try {
51  ecl::set_priority(ecl::RealTimePriority4);
52  } catch ( StandardException &e ) {
53  // dont worry about it.
54  }
55 
56  StopWatch stopwatch;
57  TimeStamp times[22];
58  unsigned int lines_to_write = 500;// Buffer::buffer_size/10 + 1;
59  float f = 33.54;
60 
61  std::cout << std::endl;
62  std::cout << "***********************************************************" << std::endl;
63  std::cout << " OFile Write" << std::endl;
64  std::cout << "***********************************************************" << std::endl;
65  std::cout << std::endl;
66 
67  OFile o_file("odude.txt",New);
68  for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
69  o_file.write("Heya Dude\n",10);
70  }
71  o_file.flush();
72  stopwatch.restart();
73  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
74  o_file.write("Heya Dude\n",10);
75  }
76  o_file.flush();
77  times[0] = stopwatch.split();
78 
79  std::cout << std::endl;
80  std::cout << "***********************************************************" << std::endl;
81  std::cout << " Shared File Write" << std::endl;
82  std::cout << "***********************************************************" << std::endl;
83  std::cout << std::endl;
84 
85  SharedFile s_file("sdude.txt",New);
86  for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
87  s_file.write("Heya Dude\n",10);
88  }
89  s_file.flush();
90  stopwatch.restart();
91  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
92  s_file.write("Heya Dude\n",10);
93  }
94  s_file.flush();
95  times[1] = stopwatch.split();
96 
97  std::cout << std::endl;
98  std::cout << "***********************************************************" << std::endl;
99  std::cout << " TextStream<OFile>" << std::endl;
100  std::cout << "***********************************************************" << std::endl;
101  std::cout << std::endl;
102 
103  TextStream<OFile> ostream;
104  ostream.device().open("dude_stream.txt",New);
105  stopwatch.restart();
106  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
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  stopwatch.restart();
117  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
118  ostream << f << "\n";
119  }
120  ostream.flush();
121  stopwatch.restart();
122  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
123  ostream << f << "\n";
124  }
125  ostream.flush();
126  times[3] = stopwatch.split();
127 
128  std::cout << std::endl;
129  std::cout << "***********************************************************" << std::endl;
130  std::cout << " std::ofstream" << std::endl;
131  std::cout << "***********************************************************" << std::endl;
132  std::cout << std::endl;
133 
134  std::ofstream cpp_ostream("dude_ofstream.txt");
135  stopwatch.restart();
136  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
137  cpp_ostream << "Heya Dude\n";
138  }
139  cpp_ostream.flush();
140  stopwatch.restart();
141  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
142  cpp_ostream << "Heya Dude\n";
143  }
144  cpp_ostream.flush();
145  times[4] = stopwatch.split();
146  stopwatch.restart();
147  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
148  cpp_ostream << f << "\n";
149  }
150  cpp_ostream.flush();
151  stopwatch.restart();
152  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
153  cpp_ostream << f << "\n";
154  }
155  cpp_ostream.flush();
156  times[5] = stopwatch.split();
157  cpp_ostream.close();
158 
159  std::cout << std::endl;
160  std::cout << "***********************************************************" << std::endl;
161  std::cout << " LogStream" << std::endl;
162  std::cout << "***********************************************************" << std::endl;
163  std::cout << std::endl;
164 
165  LogStream log_stream("dude_logstream.txt",New);
166  log_stream.disableHeader();
167  log_stream.disableTimeStamp();
168  log_stream.enableMode(Warning,"WARNING");
169 
170  stopwatch.restart();
171  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
172  LOG(log_stream,Warning) << "Heya Dude\n";
173  }
174  FLUSH(log_stream);
175  stopwatch.restart();
176  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
177  LOG(log_stream,Warning) << "Heya Dude\n";
178  }
179  FLUSH(log_stream);
180  times[9] = stopwatch.split();
181  stopwatch.restart();
182  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
183  LOG(log_stream,Warning) << f << "\n";
184  }
185  FLUSH(log_stream);
186  stopwatch.restart();
187  for ( unsigned int i = 0; i < lines_to_write; ++i ) {
188  LOG(log_stream,Warning) << f << "\n";
189  }
190  FLUSH(log_stream);
191  times[10] = stopwatch.split();
192 
193  std::cout << std::endl;
194  std::cout << "***********************************************************" << std::endl;
195  std::cout << " Times" << std::endl;
196  std::cout << "***********************************************************" << std::endl;
197  std::cout << std::endl;
198 
199  std::cout << "Writing Char Strings:" << std::endl;
200  std::cout << " OFile write : " << times[0].nsec() << " ns" << std::endl;
201  std::cout << " SharedFile write : " << times[1].nsec() << " ns" << std::endl;
202  std::cout << " OFile stream : " << times[2].nsec() << " ns" << std::endl;
203  std::cout << " LogStream : " << times[9].nsec() << " ns" << std::endl;
204  std::cout << " C++ ofstream : " << times[4].nsec() << " ns" << std::endl;
205  std::cout << "Streaming Floats:" << std::endl;
206  std::cout << " OFileStream : " << times[3].nsec() << " ns" << std::endl;
207  std::cout << " Log stream : " << times[10].nsec() << " ns" << std::endl;
208  std::cout << " C++ ofstream : " << times[5].nsec() << " ns" << std::endl;
209 
210  std::cout << std::endl;
211  std::cout << "***********************************************************" << std::endl;
212  std::cout << " Passed" << std::endl;
213  std::cout << "***********************************************************" << std::endl;
214  std::cout << std::endl;
215 
216  return 0;
217 }
main
int main()
Definition: files.cpp:49
LogMode
LogMode
Definition: files.cpp:40
log_stream.hpp
ecl::SharedFile::write
long write(const char &c)
ecl::TextStream
ecl::LogStream::enableMode
void enableMode(int mode, const std::string header="")
ecl::LogStream::disableHeader
void disableHeader()
ecl::New
New
ecl::Append
Append
f
void f(int i)
Error
@ Error
Definition: files.cpp:44
ecl::StandardException
ofile.hpp
text_stream.hpp
Warning
@ Warning
Definition: files.cpp:43
stopwatch.hpp
ecl::LogStream
ecl::SharedFile
priority.hpp
ecl::LogStream::disableTimeStamp
void disableTimeStamp()
ecl::SharedFile::flush
bool flush()
ecl::RealTimePriority4
RealTimePriority4
shared_file.hpp


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