Hi Wayne, On Mon, Oct 29, 2018 at 6:16 PM Wayne Stambaugh <stambau...@gmail.com> wrote: > > Patches 2 and 3 are merged. I merge the fixed patch when you post it.
Freshly Jenkins'ed for your consideration. Cheers, John
From be91dac4227ee6cce6e3188b3b8aebabfaa5efda Mon Sep 17 00:00:00 2001 From: John Beard <john.j.be...@gmail.com> Date: Mon, 8 Oct 2018 19:11:46 +0100 Subject: [PATCH] Add an in-memory STREAM_LINE_READER benchmark This adds an io-benchmark case of the STRING_LINE_READER class, which reads a file into a std::string, *then* reads it line by line. As expected, due to it all being in memory, this is very fast. Also fixes an issue in io_benchmark where the input file must be in the current dir. --- qa/qa_utils/stdstream_line_reader.cpp | 4 +- tools/io_benchmark/io_benchmark.cpp | 75 ++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/qa/qa_utils/stdstream_line_reader.cpp b/qa/qa_utils/stdstream_line_reader.cpp index 3f6596fdb..d473f3442 100644 --- a/qa/qa_utils/stdstream_line_reader.cpp +++ b/qa/qa_utils/stdstream_line_reader.cpp @@ -68,7 +68,7 @@ void STDISTREAM_LINE_READER::SetStream( std::istream& aStream ) IFSTREAM_LINE_READER::IFSTREAM_LINE_READER( const wxFileName& aFileName ) : - m_fStream( aFileName.GetFullName().ToUTF8() ) + m_fStream( aFileName.GetFullPath().ToUTF8() ) { if( !m_fStream.is_open() ) { @@ -79,7 +79,7 @@ IFSTREAM_LINE_READER::IFSTREAM_LINE_READER( const wxFileName& aFileName ) : SetStream( m_fStream ); - m_source = aFileName.GetFullName(); + m_source = aFileName.GetFullPath(); } diff --git a/tools/io_benchmark/io_benchmark.cpp b/tools/io_benchmark/io_benchmark.cpp index 9442d9317..0c11a96c3 100644 --- a/tools/io_benchmark/io_benchmark.cpp +++ b/tools/io_benchmark/io_benchmark.cpp @@ -123,7 +123,7 @@ static void bench_line_reader( const wxFileName& aFile, int aReps, BENCH_REPORT& { for( int i = 0; i < aReps; ++i) { - LR fstr( aFile.GetFullName() ); + LR fstr( aFile.GetFullPath() ); while( fstr.ReadLine() ) { report.linesRead++; @@ -140,7 +140,7 @@ static void bench_line_reader( const wxFileName& aFile, int aReps, BENCH_REPORT& template<typename LR> static void bench_line_reader_reuse( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - LR fstr( aFile.GetFullName() ); + LR fstr( aFile.GetFullPath() ); for( int i = 0; i < aReps; ++i) { @@ -155,6 +155,53 @@ static void bench_line_reader_reuse( const wxFileName& aFile, int aReps, BENCH_R } +/** + * Benchmark using STRING_LINE_READER on string data read into memory from a file + * using std::ifstream, but read the data fresh from the file each time + */ +static void bench_string_lr( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) +{ + for( int i = 0; i < aReps; ++i) + { + std::ifstream ifs( aFile.GetFullPath().ToStdString() ); + std::string content((std::istreambuf_iterator<char>(ifs)), + std::istreambuf_iterator<char>()); + + STRING_LINE_READER fstr( content, aFile.GetFullPath() ); + while( fstr.ReadLine() ) + { + report.linesRead++; + report.charAcc += (unsigned char) fstr.Line()[0]; + } + } +} + + +/** + * Benchmark using STRING_LINE_READER on string data read into memory from a file + * using std::ifstream + * + * The STRING_LINE_READER is not reused (it cannot be rewound), + * but the file is read only once + */ +static void bench_string_lr_reuse( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) +{ + std::ifstream ifs( aFile.GetFullPath().ToStdString() ); + std::string content((std::istreambuf_iterator<char>(ifs)), + std::istreambuf_iterator<char>()); + + for( int i = 0; i < aReps; ++i) + { + STRING_LINE_READER fstr( content, aFile.GetFullPath() ); + while( fstr.ReadLine() ) + { + report.linesRead++; + report.charAcc += (unsigned char) fstr.Line()[0]; + } + } +} + + /** * Benchmark using an INPUTSTREAM_LINE_READER with a given * wxInputStream implementation. @@ -163,11 +210,11 @@ static void bench_line_reader_reuse( const wxFileName& aFile, int aReps, BENCH_R template<typename S> static void bench_wxis( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - S fileStream( aFile.GetFullName() ); + S fileStream( aFile.GetFullPath() ); for( int i = 0; i < aReps; ++i) { - INPUTSTREAM_LINE_READER istr( &fileStream, aFile.GetFullName() ); + INPUTSTREAM_LINE_READER istr( &fileStream, aFile.GetFullPath() ); while( istr.ReadLine() ) { @@ -188,8 +235,8 @@ static void bench_wxis( const wxFileName& aFile, int aReps, BENCH_REPORT& report template<typename S> static void bench_wxis_reuse( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - S fileStream( aFile.GetFullName() ); - INPUTSTREAM_LINE_READER istr( &fileStream, aFile.GetFullName() ); + S fileStream( aFile.GetFullPath() ); + INPUTSTREAM_LINE_READER istr( &fileStream, aFile.GetFullPath() ); for( int i = 0; i < aReps; ++i) { @@ -212,12 +259,12 @@ static void bench_wxis_reuse( const wxFileName& aFile, int aReps, BENCH_REPORT& template<typename WXIS> static void bench_wxbis( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - WXIS fileStream( aFile.GetFullName() ); + WXIS fileStream( aFile.GetFullPath() ); wxBufferedInputStream bufferedStream( fileStream ); for( int i = 0; i < aReps; ++i) { - INPUTSTREAM_LINE_READER istr( &bufferedStream, aFile.GetFullName() ); + INPUTSTREAM_LINE_READER istr( &bufferedStream, aFile.GetFullPath() ); while( istr.ReadLine() ) { @@ -238,10 +285,10 @@ static void bench_wxbis( const wxFileName& aFile, int aReps, BENCH_REPORT& repor template<typename WXIS> static void bench_wxbis_reuse( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - WXIS fileStream( aFile.GetFullName() ); + WXIS fileStream( aFile.GetFullPath() ); wxBufferedInputStream bufferedStream( fileStream ); - INPUTSTREAM_LINE_READER istr( &bufferedStream, aFile.GetFullName() ); + INPUTSTREAM_LINE_READER istr( &bufferedStream, aFile.GetFullPath() ); for( int i = 0; i < aReps; ++i) { @@ -262,10 +309,12 @@ static std::vector<BENCHMARK> benchmarkList = { { 'f', bench_fstream, "std::fstream" }, { 'F', bench_fstream_reuse, "std::fstream, reused" }, - { 'r', bench_line_reader<FILE_LINE_READER>, "RICHIO" }, - { 'R', bench_line_reader_reuse<FILE_LINE_READER>, "RICHIO, reused" }, + { 'r', bench_line_reader<FILE_LINE_READER>, "RichIO FILE_L_R" }, + { 'R', bench_line_reader_reuse<FILE_LINE_READER>, "RichIO FILE_L_R, reused" }, { 'n', bench_line_reader<IFSTREAM_LINE_READER>, "std::ifstream L_R" }, { 'N', bench_line_reader_reuse<IFSTREAM_LINE_READER>, "std::ifstream L_R, reused" }, + { 's', bench_string_lr, "RichIO STRING_L_R"}, + { 'S', bench_string_lr_reuse, "RichIO STRING_L_R, reused"}, { 'w', bench_wxis<wxFileInputStream>, "wxFileIStream" }, { 'W', bench_wxis<wxFileInputStream>, "wxFileIStream, reused" }, { 'g', bench_wxis<wxFFileInputStream>, "wxFFileIStream" }, @@ -358,7 +407,7 @@ int main( int argc, char* argv[] ) os << "IO Bench Mark Util" << std::endl; - os << " Benchmark file: " << inFile.GetFullName() << std::endl; + os << " Benchmark file: " << inFile.GetFullPath() << std::endl; os << " Repetitions: " << (int) reps << std::endl; os << std::endl; -- 2.19.1
_______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp