From 0df5875a0ea49c4e7e05274d180b07f5cb56743d Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 3 Jan 2020 03:21:50 +0300 Subject: add a basic benchmark for lexer I suspect std::regex is _horribly_ slow. Will compare it to boost::regex, then decide. --- test/benchmarks/CMakeLists.txt | 12 ++++++++++++ test/benchmarks/lexer.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/benchmarks/CMakeLists.txt create mode 100644 test/benchmarks/lexer.cpp (limited to 'test/benchmarks') diff --git a/test/benchmarks/CMakeLists.txt b/test/benchmarks/CMakeLists.txt new file mode 100644 index 0000000..89d9858 --- /dev/null +++ b/test/benchmarks/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(benchmarks lexer.cpp) +set_target_properties(benchmarks PROPERTIES OUTPUT_NAME math-server-benchmarks) + +target_link_libraries(benchmarks PRIVATE lexer) +target_include_directories(benchmarks PRIVATE ../..) + +target_link_libraries(benchmarks PRIVATE benchmark benchmark_main) + +install(TARGETS benchmarks RUNTIME DESTINATION bin) +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + install(FILES "$" DESTINATION bin OPTIONAL) +endif() diff --git a/test/benchmarks/lexer.cpp b/test/benchmarks/lexer.cpp new file mode 100644 index 0000000..0f3151f --- /dev/null +++ b/test/benchmarks/lexer.cpp @@ -0,0 +1,25 @@ +#include + +#include + +class SelectionOfNumbers : public benchmark::Fixture { +protected: + std::vector m_numbers{ + "0", + "123", + "0.123", + ".123", + "1e9", + "1.87E-18", + "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + }; +}; + +BENCHMARK_F(SelectionOfNumbers, ParseStdRegex)(benchmark::State &state) { + using namespace math::server::lexer::details; + for (auto _ : state) { + for (const auto& src : m_numbers) { + parse_number(src); + } + } +} -- cgit v1.2.3