You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
libcxx
benchmarks
CMakeLists.txt
ContainerBenchmarks.hpp
GenerateInput.hpp
algorithms.bench.cpp
filesystem.bench.cpp
string.bench.cpp
stringstream.bench.cpp
unordered_set_operations.bench.cpp
util_smartptr.bench.cpp
vector_operations.bench.cpp
cmake
docs
fuzzing
include
lib
src
utils
www
.arcconfig
.clang-format
.gitignore
CMakeLists.txt
CREDITS.TXT
LICENSE.TXT
NOTES.TXT
TODO.TXT
appveyor-reqs-install.cmd
appveyor.yml
libcxxabi
libunwind
lld
lldb
llvm
openmp
polly
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mk
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
![]() |
#include <unordered_set>
|
||
|
#include <vector>
|
||
|
#include <cstdint>
|
||
|
|
||
|
#include "benchmark/benchmark_api.h"
|
||
|
#include "GenerateInput.hpp"
|
||
|
|
||
|
constexpr std::size_t MAX_STRING_LEN = 8 << 14;
|
||
|
|
||
|
// Benchmark when there is no match.
|
||
|
static void BM_StringFindNoMatch(benchmark::State &state) {
|
||
|
std::string s1(state.range(0), '-');
|
||
|
std::string s2(8, '*');
|
||
|
while (state.KeepRunning())
|
||
|
benchmark::DoNotOptimize(s1.find(s2));
|
||
|
}
|
||
|
BENCHMARK(BM_StringFindNoMatch)->Range(10, MAX_STRING_LEN);
|
||
|
|
||
|
// Benchmark when the string matches first time.
|
||
|
static void BM_StringFindAllMatch(benchmark::State &state) {
|
||
|
std::string s1(MAX_STRING_LEN, '-');
|
||
|
std::string s2(state.range(0), '-');
|
||
|
while (state.KeepRunning())
|
||
|
benchmark::DoNotOptimize(s1.find(s2));
|
||
|
}
|
||
|
BENCHMARK(BM_StringFindAllMatch)->Range(1, MAX_STRING_LEN);
|
||
|
|
||
|
// Benchmark when the string matches somewhere in the end.
|
||
|
static void BM_StringFindMatch1(benchmark::State &state) {
|
||
|
std::string s1(MAX_STRING_LEN / 2, '*');
|
||
|
s1 += std::string(state.range(0), '-');
|
||
|
std::string s2(state.range(0), '-');
|
||
|
while (state.KeepRunning())
|
||
|
benchmark::DoNotOptimize(s1.find(s2));
|
||
|
}
|
||
|
BENCHMARK(BM_StringFindMatch1)->Range(1, MAX_STRING_LEN / 4);
|
||
|
|
||
|
// Benchmark when the string matches somewhere from middle to the end.
|
||
|
static void BM_StringFindMatch2(benchmark::State &state) {
|
||
|
std::string s1(MAX_STRING_LEN / 2, '*');
|
||
|
s1 += std::string(state.range(0), '-');
|
||
|
s1 += std::string(state.range(0), '*');
|
||
|
std::string s2(state.range(0), '-');
|
||
|
while (state.KeepRunning())
|
||
|
benchmark::DoNotOptimize(s1.find(s2));
|
||
|
}
|
||
|
BENCHMARK(BM_StringFindMatch2)->Range(1, MAX_STRING_LEN / 4);
|
||
|
|
||
|
BENCHMARK_MAIN()
|