From 5c11d731cadd06204c8c6d6c1aea2253450204a8 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 6 Jan 2020 13:40:22 +0300 Subject: lexer: std:: vs boost:: for whitespace parsing Added the corresponding benchmarks too. --- test/benchmarks/lexer.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'test/benchmarks') diff --git a/test/benchmarks/lexer.cpp b/test/benchmarks/lexer.cpp index 4279d8b..3eb895c 100644 --- a/test/benchmarks/lexer.cpp +++ b/test/benchmarks/lexer.cpp @@ -2,7 +2,7 @@ #include -class SelectionOfNumbers : public benchmark::Fixture { +class NumberExamples : public benchmark::Fixture { protected: std::vector m_numbers{ "0", @@ -15,7 +15,16 @@ protected: }; }; -BENCHMARK_F(SelectionOfNumbers, ParseStdRegex)(benchmark::State& state) { +class WhitespaceExamples : public benchmark::Fixture { +protected: + std::vector m_whitespace{ + "", + " 1", + " 123", + }; +}; + +BENCHMARK_F(NumberExamples, StdParseNumber)(benchmark::State& state) { using namespace math::server::lexer::details; for (auto _ : state) { for (const auto& src : m_numbers) { @@ -24,7 +33,7 @@ BENCHMARK_F(SelectionOfNumbers, ParseStdRegex)(benchmark::State& state) { } } -BENCHMARK_F(SelectionOfNumbers, ParseBoostRegex)(benchmark::State& state) { +BENCHMARK_F(NumberExamples, BoostParseNumber)(benchmark::State& state) { using namespace math::server::lexer::details; for (auto _ : state) { for (const auto& src : m_numbers) { @@ -32,3 +41,21 @@ BENCHMARK_F(SelectionOfNumbers, ParseBoostRegex)(benchmark::State& state) { } } } + +BENCHMARK_F(WhitespaceExamples, StdParseWhitespace)(benchmark::State& state) { + using namespace math::server::lexer::details; + for (auto _ : state) { + for (const auto& src : m_whitespace) { + impl::std_parse_whitespace(src); + } + } +} + +BENCHMARK_F(WhitespaceExamples, BoostParseWhitespace)(benchmark::State& state) { + using namespace math::server::lexer::details; + for (auto _ : state) { + for (const auto& src : m_whitespace) { + impl::boost_parse_whitespace(src); + } + } +} -- cgit v1.2.3