[swift-users] Optimal String conversion to/from UTF-8 w/o null-termination?

Quinn "The Eskimo!" eskimo1 at apple.com
Mon Nov 6 11:40:43 CST 2017


On 6 Nov 2017, at 17:21, Kelvin Ma via swift-users <swift-users at swift.org> wrote:

> doesn’t the compiler like to optimize the loop out of the benchmarking code?

Yep.  I would resolve this by reading the input from a file.  For example, in the data-to-String case, you could:

1. Read lots of individual chunks of data from the file

2. Run each chunk through the `String` initialiser

3. Count how many chunks work and how many fail, so the output depends on the input

4. Print that number, which prevents the compiler optimising the whole thing away

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware




More information about the swift-users mailing list