-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance improvement with NSMutableString #3
Comments
Perhaps. I am not sure if this is actually going to be an improvement though because it all depends on how If implemented this way, would need to return the class of string that was passed in. This way, if the implementer is doing any class comparisons on it, they would not get a surprise return. So that would mean doing a |
At the very least, using NSMutableString wont leave a lot of autoreleased objects. Though you're right, I also don't think there's a lot of use case for obfuscated strings anyway for this to matter. About the class comparisons you were saying, wouldn't changing the methods to return NSMutableString instead be enough to state that behavior? Just to be safe, on the NSString category maybe instead of Anyway I was just sharing some ideas. I have obfuscated strings as well, but with macros that XOR the characters out. Your method certainly looks cleaner though, so maybe I'll send a pull request when I actually have the chance to use it :) |
First of all, thanks for this handy category @coneybeare. I've been also wondering about the speed improvements when using I made up some random strings, with various lengths and created the same strings using the category 5 times, each time measuring the time and new average of specific string. Here are the results when I used the category downloaded from Github without any modifications:
Now I modified the category, so it instead is a category on
So as you can see, when using the category on a mutable string, it was 31% to 61% faster when creating the strings. I think this is a significant gain in performance. I would be happy to make a pull request with the changes, however don't forget this will probably require a little change in how people use this category as it will have to be a So, what do you guys think? :) You can find all results (all passes & devices) on Pastebin. |
Wow, thanks for doing all this. Please send a pull request with the changes to start, then we can discuss more specific implementation in the comment threads for the PR. |
You have an interesting library here. I think you can improve memory usage and performance by implementing categories on both NSString and NSMutableString. On the NSString category return
[self mutableCopy]
, then on NSMutableString one call[self appendString:<letter>]
and return self.The text was updated successfully, but these errors were encountered: