Re: Repetitive Appending of Strings
Re: Repetitive Appending of Strings
- Subject: Re: Repetitive Appending of Strings
- From: Jean-Daniel Dupas <email@hidden>
- Date: Wed, 13 Feb 2008 00:54:00 +0100
Le 13 févr. 08 à 00:25, Adam P Jenkins a écrit :
Yeah, it was about 0.007 seconds without the reserve() call, but
since I was doing the equivalent of reserve with the NSMutableData
case, it seems more even to do the same with the vector<char> case.
As for clear(), I tried changing the code to use the swap trick you
showed, and the timing results were the same. I don't understand
why the vector[i]=ch example runs faster than the raw array access
example. It must just be an artifact of some allocation and caching
behavior. I'm fine with just calling them the same.
In any case it shows that for small methods where you don't actually
need dynamic dispatch, C++'s inlining and non-virtual methods can
yield much faster code than you can get with Objective-C classes.
Adam
The String way is slow due to the format parsing. For bench I think I
will do this:
{
UniChar uch = (i % 10) + '0';
CFStringAppendCharacters((CFMutableStringRef)str, &uch, 1);
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden