Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3440614
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:27:10+00:00 2026-05-18T08:27:10+00:00

My old Trimming function: string TailTrimString (const string & sSource, const char *chars) {

  • 0

My old Trimming function:

string TailTrimString (const string & sSource, const char *chars) {
  size_t End = sSource.find_last_not_of(chars);
  if (End == string::npos) {
    // only "*chars"
    return "";
  }
  if (End == sSource.size() - 1) {
    // noting to trim
    return sSource;
  }
  return sSource.substr(0, End + 1);
}

Instead of it I’ve decided to use boost, and wrote the trivial:

string TailTrimString (const string & sSource, const char *chars) {
    return boost::algorithm::trim_right_copy_if(sSource,boost::algorithm::is_any_of(chars));
}

And I was amazed to find out that the new function works much slower.
I’ve done some profiling, and I see that the function is_any_of is very slow.

Is it possible that boost’s implementation works slower than my quite straightforward implementation? Is there anything I should use instead of is_any_of in order to improve the performance?

I also found a discussion on this matter in the boost’s mailing list, but I am still not sure on how can I improve the performance of my code.

The boost version that I use is 1.38, which is quite old, but I guess this code didn’t change too much since then.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:27:11+00:00Added an answer on May 18, 2026 at 8:27 am

    it possible that boost’s implementation works slower than my quite straightforward implementation?

    Of course.

    Is there anything I should use instead of is_any_of in order to improve the performance?

    Yeah — your original code. You said nothing about it having a defect, or the reason why you re-implemented it using boost. If there was no defect in the original code, then there was no valid reason to chuck the original implementation.

    Introducing Boost to a codebase makes sense. It brings a lot of functionality that can be helpful. But gutting a function for the sole purpose of using a new technology is a big rookie mistake.

    EDIT:

    In response to your comment:

    I still don’t understand, why boost’s performance is worse.

    A hand-crafted function that is designed to do one specific job for one specific application will often be faster than a generic solution. Boost is a great library of generic tools that can save a lot of programming and a lot of defects. But its generic. You may only need to trim your string in a specific way, but Boost handles everything. That takes time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My old Boost code: std::string CombinePath(const char* left, const char* right) { boost::filesystem::path p
The old JS SDK had a function called FB.ensureInit. The new SDK does not
The old, C style cvMat matrices could be passed to the cvSave() function for
Old title: Included PHP doesn't work with JQuery and IE in a function as
OLD : private string Check_long(string input) { input = input.Replace(cool, supercool); input = input.Replace(cool1,
I'll redefine my old unanswered & messy Question 'cause i'm begging for Your help.
In old API the init function required path to xdreceiver and now i see
Old question My understanding is that C# has in some sense HashSet and set
An old Direct3D book says ...you can achieve an acceptable frame rate with hardware
Scenario: old legacy code in rpg have to consume data from a new web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.