KiCad PCB EDA Suite
Loading...
Searching...
No Matches
io_benchmark.cpp File Reference
#include <wx/wx.h>
#include <richio.h>
#include <chrono>
#include <ios>
#include <functional>
#include <iostream>
#include <fstream>
#include <wx/wfstream.h>
#include <wx/filename.h>
#include <qa_utils/stdstream_line_reader.h>
#include <qa_utils/utility_registry.h>

Go to the source code of this file.

Classes

struct  BENCH_REPORT
 
struct  BENCHMARK
 

Typedefs

using CLOCK = std::chrono::steady_clock
 
using TIME_PT = std::chrono::time_point< CLOCK >
 
using BENCH_FUNC = std::function< void(const wxFileName &, int, BENCH_REPORT &)>
 

Functions

static void bench_fstream (const wxFileName &aFile, int aReps, BENCH_REPORT &report)
 Benchmark using a raw std::ifstream, with no LINE_READER wrapper.
 
static void bench_fstream_reuse (const wxFileName &aFile, int aReps, BENCH_REPORT &report)
 Benchmark using a raw std::ifstream, with no LINE_READER wrapper.
 
template<typename LR >
static void bench_line_reader (const wxFileName &aFile, int aReps, BENCH_REPORT &report)
 Benchmark using a given LINE_READER implementation.
 
template<typename LR >
static void bench_line_reader_reuse (const wxFileName &aFile, int aReps, BENCH_REPORT &report)
 Benchmark using a given LINE_READER implementation.
 
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, but read the data fresh from the file each time.
 
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.
 
template<typename S >
static void bench_wxis (const wxFileName &aFile, int aReps, BENCH_REPORT &report)
 Benchmark using an INPUTSTREAM_LINE_READER with a given wxInputStream implementation.
 
template<typename S >
static void bench_wxis_reuse (const wxFileName &aFile, int aReps, BENCH_REPORT &report)
 Benchmark using an INPUTSTREAM_LINE_READER with a given wxInputStream implementation.
 
template<typename WXIS >
static void bench_wxbis (const wxFileName &aFile, int aReps, BENCH_REPORT &report)
 Benchmark using a INPUTSTREAM_LINE_READER with a given wxInputStream implementation, buffered with wxBufferedInputStream.
 
template<typename WXIS >
static void bench_wxbis_reuse (const wxFileName &aFile, int aReps, BENCH_REPORT &report)
 Benchmark using a INPUTSTREAM_LINE_READER with a given wxInputStream implementation, buffered with wxBufferedInputStream.
 
static wxString getBenchFlags ()
 Construct string of all flags used for specifying benchmarks on the command line.
 
static wxString getBenchDescriptions ()
 Usage description of a benchmakr spec.
 
BENCH_REPORT executeBenchMark (const BENCHMARK &aBenchmark, int aReps, const wxFileName &aFilename)
 
int io_benchmark_func (int argc, char *argv[])
 

Variables

static std::vector< BENCHMARKbenchmarkList
 List of available benchmarks.
 
static bool registered
 

Typedef Documentation

◆ BENCH_FUNC

using BENCH_FUNC = std::function<void(const wxFileName&, int, BENCH_REPORT&)>

Definition at line 60 of file io_benchmark.cpp.

◆ CLOCK

using CLOCK = std::chrono::steady_clock

Definition at line 41 of file io_benchmark.cpp.

◆ TIME_PT

using TIME_PT = std::chrono::time_point<CLOCK>

Definition at line 42 of file io_benchmark.cpp.

Function Documentation

◆ bench_fstream()

static void bench_fstream ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

Benchmark using a raw std::ifstream, with no LINE_READER wrapper.

The stream is recreated for each cycle.

Definition at line 75 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, and BENCH_REPORT::linesRead.

◆ bench_fstream_reuse()

static void bench_fstream_reuse ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

Benchmark using a raw std::ifstream, with no LINE_READER wrapper.

The stream is not recreated for each cycle, just reset.

Definition at line 98 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, and BENCH_REPORT::linesRead.

◆ bench_line_reader()

template<typename LR >
static void bench_line_reader ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

Benchmark using a given LINE_READER implementation.

The LINE_READER is recreated for each cycle.

Definition at line 123 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, BENCH_REPORT::linesRead, and LR.

◆ bench_line_reader_reuse()

template<typename LR >
static void bench_line_reader_reuse ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

Benchmark using a given LINE_READER implementation.

The LINE_READER is rewound for each cycle, not recreated.

Definition at line 142 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, BENCH_REPORT::linesRead, and LR.

◆ bench_string_lr()

static void bench_string_lr ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

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.

Definition at line 163 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, LINE_READER::Line(), BENCH_REPORT::linesRead, and STRING_LINE_READER::ReadLine().

◆ bench_string_lr_reuse()

static void bench_string_lr_reuse ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

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

Definition at line 188 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, LINE_READER::Line(), BENCH_REPORT::linesRead, and STRING_LINE_READER::ReadLine().

◆ bench_wxbis()

template<typename WXIS >
static void bench_wxbis ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

Benchmark using a INPUTSTREAM_LINE_READER with a given wxInputStream implementation, buffered with wxBufferedInputStream.

The wxInputStream is recreated for each cycle.

Definition at line 261 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, LINE_READER::Line(), BENCH_REPORT::linesRead, and INPUTSTREAM_LINE_READER::ReadLine().

◆ bench_wxbis_reuse()

template<typename WXIS >
static void bench_wxbis_reuse ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

Benchmark using a INPUTSTREAM_LINE_READER with a given wxInputStream implementation, buffered with wxBufferedInputStream.

The wxInputStream is reset for each cycle.

Definition at line 287 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, LINE_READER::Line(), BENCH_REPORT::linesRead, and INPUTSTREAM_LINE_READER::ReadLine().

◆ bench_wxis()

template<typename S >
static void bench_wxis ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

Benchmark using an INPUTSTREAM_LINE_READER with a given wxInputStream implementation.

The wxInputStream is recreated for each cycle.

Definition at line 212 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, LINE_READER::Line(), BENCH_REPORT::linesRead, and INPUTSTREAM_LINE_READER::ReadLine().

◆ bench_wxis_reuse()

template<typename S >
static void bench_wxis_reuse ( const wxFileName &  aFile,
int  aReps,
BENCH_REPORT report 
)
static

Benchmark using an INPUTSTREAM_LINE_READER with a given wxInputStream implementation.

The wxInputStream is reset for each cycle.

Definition at line 237 of file io_benchmark.cpp.

References BENCH_REPORT::charAcc, LINE_READER::Line(), BENCH_REPORT::linesRead, and INPUTSTREAM_LINE_READER::ReadLine().

◆ executeBenchMark()

BENCH_REPORT executeBenchMark ( const BENCHMARK aBenchmark,
int  aReps,
const wxFileName &  aFilename 
)

Definition at line 363 of file io_benchmark.cpp.

References BENCH_REPORT::benchDurMs, and BENCHMARK::func.

Referenced by io_benchmark_func().

◆ getBenchDescriptions()

static wxString getBenchDescriptions ( )
static

Usage description of a benchmakr spec.

Definition at line 350 of file io_benchmark.cpp.

References benchmarkList.

Referenced by io_benchmark_func().

◆ getBenchFlags()

static wxString getBenchFlags ( )
static

Construct string of all flags used for specifying benchmarks on the command line.

Definition at line 334 of file io_benchmark.cpp.

References benchmarkList.

Referenced by io_benchmark_func().

◆ io_benchmark_func()

Variable Documentation

◆ benchmarkList

std::vector<BENCHMARK> benchmarkList
static
Initial value:
=
{
{ 'f', bench_fstream, "std::fstream" },
{ 'F', bench_fstream_reuse, "std::fstream, 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" },
{ 'G', bench_wxis_reuse<wxFFileInputStream>, "wxFFileIStream, reused" },
{ 'b', bench_wxbis<wxFileInputStream>, "wxFileIStream. buf'd" },
{ 'B', bench_wxbis_reuse<wxFileInputStream>, "wxFileIStream, buf'd, reused" },
{ 'c', bench_wxbis<wxFFileInputStream>, "wxFFileIStream. buf'd" },
{ 'C', bench_wxbis_reuse<wxFFileInputStream>, "wxFFileIStream, buf'd, reused" },
}
static void bench_fstream_reuse(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using a raw std::ifstream, with no LINE_READER wrapper.
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_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,...
static void bench_fstream(const wxFileName &aFile, int aReps, BENCH_REPORT &report)
Benchmark using a raw std::ifstream, with no LINE_READER wrapper.

List of available benchmarks.

Definition at line 309 of file io_benchmark.cpp.

Referenced by getBenchDescriptions(), getBenchFlags(), and io_benchmark_func().

◆ registered

bool registered
static
Initial value:
"io_benchmark",
"Benchmark various kinds of IO methods",
} )
static bool Register(const KI_TEST::UTILITY_PROGRAM &aProgInfo)
Register a utility program factory function against an ID string.
int io_benchmark_func(int argc, char *argv[])

Definition at line 425 of file io_benchmark.cpp.