Swift string iteration and character comparison is unbelievably slow

Originator:brian.nickel
Number:rdar://18492631 Date Originated:29-Sep-2014 02:30 PM
Status:Open Resolved:
Product:OS X SDK Product Version:
Classification: Reproducible:
 
Summary:
I ported a Markdown implementation from JavaScript to Swift and in some basic testing it is about 65 times slower. (See  https://github.com/bnickel/CommonMark.swift).

I wrote a much simpler experiment where I generate 100,000 character ASCII representable and 100,000 composed character (450,000 unichar) strings and do an iterative character search.  In the ASCII case, Swift shouldn't be doing much more work than Objective-C/C and in the second case it should.  In both cases however, Swift is hundreds of times slower.  The test code is attached along with the time profile I obtained during it.  They can also be found at https://github.com/bnickel/Simple-Swift.String-Performance-Test

Steps to Reproduce:
Iterate through and compare the character at the index with another character (perhaps by running the attached tests).

Expected Results:
Swift scans the string around as fast as Objective-C.

Actual Results:
Swift is *way* slower.

Version:
Yosemite, Xcode 6.1 beta

Notes:


Configuration:
Tested on a 2013 MBP

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!