Skip to content

Conversation

@jeking3
Copy link
Contributor

@jeking3 jeking3 commented Jun 24, 2025

Refactored is_palindrome to use std::equal yielding a 58% performance gain in limited testing (x86_64, gcc 12.2). This has fewer branches and leverages the optimization already done on the std::equal implementation.

Before: 6.953285 secs

jking@pulsar:~/boost/libs/algorithm/performance$ ../../../bin.v2/libs/algorithm/performance/perf_is_palindrome.test/gcc-12/release/x86_64/link-static/perf_is_palindrome
Total runs: 12000000
Total palindromes found: 6000000
Total elapsed time: 6.95016 seconds
Average time per is_palindrome: 0.57918 microseconds
jking@pulsar:~/boost/libs/algorithm/performance$ ../../../bin.v2/libs/algorithm/performance/perf_is_palindrome.test/gcc-12/release/x86_64/link-static/perf_is_palindrome
Total runs: 12000000
Total palindromes found: 6000000
Total elapsed time: 6.95641 seconds
Average time per is_palindrome: 0.579701 microseconds

After: 2.915925 secs

jking@pulsar:~/boost/libs/algorithm/performance$ ../../../bin.v2/libs/algorithm/performance/perf_is_palindrome.test/gcc-12/release/x86_64/link-static/perf_is_palindrome
Total runs: 12000000
Total palindromes found: 6000000
Total elapsed time: 2.92422 seconds
Average time per is_palindrome: 0.243685 microseconds
jking@pulsar:~/boost/libs/algorithm/performance$ ../../../bin.v2/libs/algorithm/performance/perf_is_palindrome.test/gcc-12/release/x86_64/link-static/perf_is_palindrome
Total runs: 12000000
Total palindromes found: 6000000
Total elapsed time: 2.90763 seconds
Average time per is_palindrome: 0.242302 microseconds

Yielding a 58.06% performance gain.

Refactored is_palindrome to use std::equal yielding a 57% performance
gain in limited testing (x86_64, gcc 12.2).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants