30#include <wx/wfstream.h>
31#include <wx/filename.h>
37using CLOCK = std::chrono::steady_clock;
38using TIME_PT = std::chrono::time_point<CLOCK>;
75 for(
int i = 0; i < aReps; ++i)
77 std::ifstream fstr( aFile.GetFullPath().fn_str() );
79 while( getline( fstr, line ) )
82 report.
charAcc += (
unsigned char) line[0];
97 std::ifstream fstr( aFile.GetFullPath().fn_str() );
99 for(
int i = 0; i < aReps; ++i)
101 while( getline( fstr, line ) )
104 report.
charAcc += (
unsigned char) line[0];
107 fstr.seekg(0, std::ios::beg) ;
121 for(
int i = 0; i < aReps; ++i)
123 LR fstr( aFile.GetFullPath() );
124 while( fstr.ReadLine() )
127 report.
charAcc += (
unsigned char) fstr.Line()[0];
140 LR fstr( aFile.GetFullPath() );
141 for(
int i = 0; i < aReps; ++i)
144 while( fstr.ReadLine() )
147 report.
charAcc += (
unsigned char) fstr.Line()[0];
161 for(
int i = 0; i < aReps; ++i)
163 std::ifstream ifs( aFile.GetFullPath().ToStdString() );
164 std::string content((std::istreambuf_iterator<char>(ifs)),
165 std::istreambuf_iterator<char>());
186 std::ifstream ifs( aFile.GetFullPath().ToStdString() );
187 std::string content((std::istreambuf_iterator<char>(ifs)),
188 std::istreambuf_iterator<char>());
190 for(
int i = 0; i < aReps; ++i)
210 S fileStream( aFile.GetFullPath() );
212 for(
int i = 0; i < aReps; ++i)
222 fileStream.SeekI( 0 );
235 S fileStream( aFile.GetFullPath() );
238 for(
int i = 0; i < aReps; ++i)
246 fileStream.SeekI( 0 );
256template<
typename WXIS>
259 WXIS fileStream( aFile.GetFullPath() );
260 wxBufferedInputStream bufferedStream( fileStream );
262 for(
int i = 0; i < aReps; ++i)
272 fileStream.SeekI( 0 );
282template<
typename WXIS>
285 WXIS fileStream( aFile.GetFullPath() );
286 wxBufferedInputStream bufferedStream( fileStream );
290 for(
int i = 0; i < aReps; ++i)
298 fileStream.SeekI( 0 );
336 flags << bmark.triggerChar;
352 desc <<
" " << bmark.triggerChar <<
": " << bmark.name <<
"\n";
360 const wxFileName& aFilename )
365 aBenchmark.
func( aFilename, aReps, report );
368 using std::chrono::milliseconds;
369 using std::chrono::duration_cast;
371 report.
benchDurMs = duration_cast<milliseconds>(
end - start );
379 auto& os = std::cout;
383 os <<
"Usage: " << argv[0] <<
" <FILE> <REPS> [" <<
getBenchFlags() <<
"]\n\n";
384 os <<
"Benchmarks:\n";
389 wxFileName inFile( argv[1] );
392 wxString( argv[2] ).ToLong( &reps );
399 os <<
"IO Bench Mark Util" << std::endl;
401 os <<
" Benchmark file: " << inFile.GetFullPath() << std::endl;
402 os <<
" Repetitions: " << (int) reps << std::endl;
407 if( bench.size() && !bench.Contains( bmark.triggerChar ) )
412 os << wxString::Format(
"%-30s %u lines, acc: %u in %u ms",
423 "Benchmark various kinds of IO methods",
char * Line() const
Return a pointer to the last line that was read in.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
static bool Register(const KI_TEST::UTILITY_PROGRAM &aProgInfo)
Register a utility program factory function against an ID string.
static void bench_fstream_reuse(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using a raw std::ifstream, with no LINE_READER wrapper.
int io_benchmark_func(int argc, char *argv[])
static void bench_line_reader(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using a given LINE_READER implementation.
static wxString getBenchFlags()
Construct string of all flags used for specifying benchmarks on the command line.
BENCH_REPORT executeBenchMark(const BENCHMARK &aBenchmark, int aReps, const wxFileName &aFilename)
static void bench_wxis_reuse(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using an INPUTSTREAM_LINE_READER with a given wxInputStream implementation.
static void bench_line_reader_reuse(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using a given LINE_READER implementation.
std::function< void(const wxFileName &, int, BENCH_REPORT &)> BENCH_FUNC
static void bench_wxbis(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using a INPUTSTREAM_LINE_READER with a given wxInputStream implementation,...
static void bench_string_lr_reuse(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using STRING_LINE_READER on string data read into memory from a file using std::ifstream.
static void bench_wxbis_reuse(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using a INPUTSTREAM_LINE_READER with a given wxInputStream implementation,...
std::chrono::time_point< CLOCK > TIME_PT
static void bench_string_lr(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using STRING_LINE_READER on string data read into memory from a file using std::ifstream,...
std::chrono::steady_clock CLOCK
static void bench_fstream(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using a raw std::ifstream, with no LINE_READER wrapper.
static std::vector< BENCHMARK > benchmarkList
List of available benchmarks.
static void bench_wxis(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using an INPUTSTREAM_LINE_READER with a given wxInputStream implementation.
static wxString getBenchDescriptions()
Usage description of a benchmakr spec.
@ BAD_CMDLINE
The command line was not correct for the tool.
unsigned charAcc
Char accumulator, used to prevent compilers optimising away otherwise unused line buffers,...
std::chrono::milliseconds benchDurMs