Add simple wxRegEx benchmark
Allow testing speed of some simple regex operations to compare the speed of the currently used regex library with some other alternatives.
This commit is contained in:
parent
8be998861d
commit
020b5f7383
@ -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
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
ipcclient.cpp
|
||||
log.cpp
|
||||
mbconv.cpp
|
||||
regex.cpp
|
||||
strings.cpp
|
||||
tls.cpp
|
||||
printfbench.cpp
|
||||
|
@ -838,6 +838,10 @@
|
||||
RelativePath=".\printfbench.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\regex.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\strings.cpp"
|
||||
>
|
||||
|
@ -810,6 +810,10 @@
|
||||
RelativePath=".\printfbench.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\regex.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\strings.cpp"
|
||||
>
|
||||
|
@ -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) $<
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
74
tests/benchmarks/regex.cpp
Normal file
74
tests/benchmarks/regex.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/benchmarks/regex.cpp
|
||||
// Purpose: wxRegEx benchmarks
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2018-11-15
|
||||
// Copyright: (c) 2018 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// 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("<td>[^<]*</td>", 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"
|
||||
}
|
Loading…
Reference in New Issue
Block a user