diff --git a/tests/benchmarks/Makefile.in b/tests/benchmarks/Makefile.in index 1945ccfe18..e7842cc239 100644 --- a/tests/benchmarks/Makefile.in +++ b/tests/benchmarks/Makefile.in @@ -57,6 +57,7 @@ BENCH_OBJECTS = \ bench_ipcclient.o \ bench_log.o \ bench_mbconv.o \ + bench_regex.o \ bench_strings.o \ bench_tls.o \ bench_printfbench.o @@ -299,6 +300,9 @@ bench_log.o: $(srcdir)/log.cpp bench_mbconv.o: $(srcdir)/mbconv.cpp $(CXXC) -c -o $@ $(BENCH_CXXFLAGS) $(srcdir)/mbconv.cpp +bench_regex.o: $(srcdir)/regex.cpp + $(CXXC) -c -o $@ $(BENCH_CXXFLAGS) $(srcdir)/regex.cpp + bench_strings.o: $(srcdir)/strings.cpp $(CXXC) -c -o $@ $(BENCH_CXXFLAGS) $(srcdir)/strings.cpp diff --git a/tests/benchmarks/bench.bkl b/tests/benchmarks/bench.bkl index f3efa94295..ed17be45fc 100644 --- a/tests/benchmarks/bench.bkl +++ b/tests/benchmarks/bench.bkl @@ -16,6 +16,7 @@ ipcclient.cpp log.cpp mbconv.cpp + regex.cpp strings.cpp tls.cpp printfbench.cpp diff --git a/tests/benchmarks/bench_vc8_bench.vcproj b/tests/benchmarks/bench_vc8_bench.vcproj index 59ea520090..80b87940c3 100644 --- a/tests/benchmarks/bench_vc8_bench.vcproj +++ b/tests/benchmarks/bench_vc8_bench.vcproj @@ -838,6 +838,10 @@ RelativePath=".\printfbench.cpp" > + + diff --git a/tests/benchmarks/bench_vc9_bench.vcproj b/tests/benchmarks/bench_vc9_bench.vcproj index 04a316aada..049dd37fb9 100644 --- a/tests/benchmarks/bench_vc9_bench.vcproj +++ b/tests/benchmarks/bench_vc9_bench.vcproj @@ -810,6 +810,10 @@ RelativePath=".\printfbench.cpp" > + + diff --git a/tests/benchmarks/makefile.gcc b/tests/benchmarks/makefile.gcc index 3bfb0a06cf..df40d939ce 100644 --- a/tests/benchmarks/makefile.gcc +++ b/tests/benchmarks/makefile.gcc @@ -36,6 +36,7 @@ BENCH_OBJECTS = \ $(OBJS)\bench_ipcclient.o \ $(OBJS)\bench_log.o \ $(OBJS)\bench_mbconv.o \ + $(OBJS)\bench_regex.o \ $(OBJS)\bench_strings.o \ $(OBJS)\bench_tls.o \ $(OBJS)\bench_printfbench.o @@ -310,6 +311,9 @@ $(OBJS)\bench_log.o: ./log.cpp $(OBJS)\bench_mbconv.o: ./mbconv.cpp $(CXX) -c -o $@ $(BENCH_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\bench_regex.o: ./regex.cpp + $(CXX) -c -o $@ $(BENCH_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\bench_strings.o: ./strings.cpp $(CXX) -c -o $@ $(BENCH_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/benchmarks/makefile.vc b/tests/benchmarks/makefile.vc index 948b2813d8..9b0a130818 100644 --- a/tests/benchmarks/makefile.vc +++ b/tests/benchmarks/makefile.vc @@ -37,6 +37,7 @@ BENCH_OBJECTS = \ $(OBJS)\bench_ipcclient.obj \ $(OBJS)\bench_log.obj \ $(OBJS)\bench_mbconv.obj \ + $(OBJS)\bench_regex.obj \ $(OBJS)\bench_strings.obj \ $(OBJS)\bench_tls.obj \ $(OBJS)\bench_printfbench.obj @@ -698,6 +699,9 @@ $(OBJS)\bench_log.obj: .\log.cpp $(OBJS)\bench_mbconv.obj: .\mbconv.cpp $(CXX) /c /nologo /TP /Fo$@ $(BENCH_CXXFLAGS) .\mbconv.cpp +$(OBJS)\bench_regex.obj: .\regex.cpp + $(CXX) /c /nologo /TP /Fo$@ $(BENCH_CXXFLAGS) .\regex.cpp + $(OBJS)\bench_strings.obj: .\strings.cpp $(CXX) /c /nologo /TP /Fo$@ $(BENCH_CXXFLAGS) .\strings.cpp diff --git a/tests/benchmarks/regex.cpp b/tests/benchmarks/regex.cpp new file mode 100644 index 0000000000..c2ca70fa98 --- /dev/null +++ b/tests/benchmarks/regex.cpp @@ -0,0 +1,74 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: tests/benchmarks/regex.cpp +// Purpose: wxRegEx benchmarks +// Author: Vadim Zeitlin +// Created: 2018-11-15 +// Copyright: (c) 2018 Vadim Zeitlin +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/ffile.h" +#include "wx/regex.h" + +#include "bench.h" + +// ---------------------------------------------------------------------------- +// Benchmark relative costs of compiling and matching for a simple regex +// ---------------------------------------------------------------------------- + +static const char* const RE_SIMPLE = "."; + +BENCHMARK_FUNC(RECompile) +{ + return wxRegEx(RE_SIMPLE).IsValid(); +} + +BENCHMARK_FUNC(REMatch) +{ + static wxRegEx re(RE_SIMPLE); + return re.Matches("foo"); +} + +BENCHMARK_FUNC(RECompileAndMatch) +{ + return wxRegEx(RE_SIMPLE).Matches("foo"); +} + +// ---------------------------------------------------------------------------- +// Benchmark the cost of using a more complicated regex +// ---------------------------------------------------------------------------- + +namespace +{ + +// Use the contents of an already existing test file. +const wxString& GetTestText() +{ + static wxString text; + if ( text.empty() ) + { + wxFFile("htmltest.html").ReadAll(&text); + } + + return text; +} + +} // anonymous namespace + +BENCHMARK_FUNC(REFindTD) +{ + // This is too simplistic, but good enough for benchmarking. + static wxRegEx re("[^<]*", wxRE_ICASE | wxRE_NEWLINE); + + int matches = 0; + for ( const wxChar* p = GetTestText().c_str(); re.Matches(p); ++matches ) + { + size_t start, len; + if ( !re.GetMatch(&start, &len) ) + return false; + + p += start + len; + } + + return matches == 21; // result of "grep -c" +}