amayne / SwiftString

A comprehensive, lightweight string extension for Swift
MIT License
1.62k stars 141 forks source link

Stash formatters in thread-local storage for performance. #19

Closed peyton closed 8 years ago

peyton commented 8 years ago

Hey, NS*Formatter initialization is expensive. This PR caches formatters in thread-local storage.

Tested a few methods on my MBP with -Os optimization:

Method Speedup
.isNumeric() 84%
.toDouble() 51%
.toDate() 58%

With thousands of strings, the speedup amounts to seconds.