Skip to content

Commit

Permalink
benchmark: Fix palindrome benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
oboukli committed Jul 4, 2024
1 parent ccf5bcf commit ef46829
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions benchmark/palindrome_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
#include "forfun/palindrome.hpp"
#include "forfun_c/palindrome.h"

using std::string_view_literals::operator""sv;

inline constexpr std::string_view const palindrome{
"oooooooooooooooooooooooooooooooooooooooooooooooooo"
"oooooooooooooooooooooooooooooooooooooooooooooooooo"sv};

TEST_CASE("Palindrome benchmarking", "[benchmark][palindrome]")
{
using std::string_view_literals::operator""sv;

using namespace forfun::palindrome;

std::string_view palindrome{
"oooooooooooooooooooooooooooooooooooooooooooooooooo"
"oooooooooooooooooooooooooooooooooooooooooooooooooo"sv};

SECTION("case-sensitive")
{
ankerl::nanobench::Bench()
Expand All @@ -34,7 +34,7 @@ TEST_CASE("Palindrome benchmarking", "[benchmark][palindrome]")

.run(
NAMEOF_RAW(::is_palindrome).c_str(),
[]() {
[&palindrome]() {
auto const r{::is_palindrome(
palindrome.data(), palindrome.length())};

Expand All @@ -43,15 +43,15 @@ TEST_CASE("Palindrome benchmarking", "[benchmark][palindrome]")

.run(
NAMEOF_RAW(functional::is_palindrome<char>).c_str(),
[]() {
[&palindrome]() {
auto const r{functional::is_palindrome(palindrome)};

ankerl::nanobench::doNotOptimizeAway(r);
})

.run(
NAMEOF_RAW(functional::bloated::is_palindrome<char>).c_str(),
[]() {
[&palindrome]() {
auto const r{
functional::bloated::is_palindrome(palindrome)};

Expand All @@ -60,15 +60,15 @@ TEST_CASE("Palindrome benchmarking", "[benchmark][palindrome]")

.run(
NAMEOF_RAW(iterator_based::is_palindrome<char>).c_str(),
[]() {
[&palindrome]() {
auto const r{iterator_based::is_palindrome(palindrome)};

ankerl::nanobench::doNotOptimizeAway(r);
})

.run(
NAMEOF_RAW(raw::is_palindrome<char>).c_str(),
[]() {
[&palindrome]() {
auto const r{raw::is_palindrome(palindrome)};

ankerl::nanobench::doNotOptimizeAway(r);
Expand All @@ -86,7 +86,7 @@ TEST_CASE("Palindrome benchmarking", "[benchmark][palindrome]")

.run(
NAMEOF_RAW(::is_palindrome_ci).c_str(),
[]() {
[&palindrome]() {
auto const r{::is_palindrome_ci(
palindrome.data(), palindrome.length())};

Expand All @@ -95,7 +95,7 @@ TEST_CASE("Palindrome benchmarking", "[benchmark][palindrome]")

.run(
NAMEOF_RAW(functional::bloated::is_palindrome_ci).c_str(),
[]() {
[&palindrome]() {
auto const r{
functional::bloated::is_palindrome_ci(palindrome)};

Expand All @@ -104,15 +104,15 @@ TEST_CASE("Palindrome benchmarking", "[benchmark][palindrome]")

.run(
NAMEOF_RAW(iterator_based::is_palindrome_ci).c_str(),
[]() {
[&palindrome]() {
auto const r{iterator_based::is_palindrome_ci(palindrome)};

ankerl::nanobench::doNotOptimizeAway(r);
})

.run(
NAMEOF_RAW(raw::is_palindrome_ci).c_str(),
[]() {
[&palindrome]() {
auto const r{raw::is_palindrome_ci(palindrome)};

ankerl::nanobench::doNotOptimizeAway(r);
Expand Down

0 comments on commit ef46829

Please sign in to comment.