othyn / DateStrings

A Swift 5 Date extension library that adds helpful string accessors and a string based initialiser. With new methods and properties that make getting a string from a Date easy.
MIT License
7 stars 2 forks source link

Actually implement caching of DateFormatter #1

Open othyn opened 4 years ago

othyn commented 4 years ago

Benchmarks and advice still overwhelmingly recommend caching DateFormatter for large speed improvements, anywhere from 5x to 20x.

To some extent, it appears you can abuse Swift's handling of static computed properties to implement this.

othyn commented 4 years ago

Also, in its current implementation, it is 'caching' and reusing the instance of DateFormatter within the scope of the file, but this can be expanded and maybe instead provide an extension of DateFormatter to return a static instance for these to use?