|
Boost Users : |
Subject: Re: [Boost-users] the problem about boost trim function in multi-thread
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2012-06-19 11:02:31
On Jun 19, 2012, at 7:39 AM, Igor R wrote:
>> I use boost trim function and find it perform very well in single-thread
>> environment.
>>
>> But when I call trim function in multi-thread environment, it will have a
>> poor performance.
>
>
> Perhaps, it's because boot::trim() uses std::locale(), which involves
> a lot of locks in a multi-threaded environment. But try analysing it
> with a performance profiler.
That should be really easy to test.
How does your test code perform if you change it to this:
void *TrimNString(void *arg) {
string base ="fdsffdsafdsa";
locale loc = locale();
for(int i = 0; i != 50000000;i++)
{
string str = base;
trim(str, loc);
}
return 0;
}
Note also that trim calls the locale to look for whitespace, which is more flexible than your test for " \r\n\t".
That's probably a significant performance difference, too.
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net