[swift-users] Alternative to UnicodeScalar
Proyb P
proyb6 at gmail.com
Sat Apr 8 11:19:24 CDT 2017
I have found this took about 0.001s to print 256 characters
Compare to Python took 0.000016s to print 256 characters, see F8 code and
have modify to run only one call instead of 1000 iterations.
https://gist.github.com/anonymous/18e372e8d0173e77b5c405920d4d3080
As this is frequently use for server-side swift that will definitely
affected by expensive call, are there any alternative solution for
converting Int to character close to Python timing?
import Foundation
var display: String = ""
func printTimeElapsedWhenRunningCode(title: String, operation: ()->()) {
let startTime = CFAbsoluteTimeGetCurrent()
operation()
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
print("Time elapsed for \(title): \(timeElapsed) s")
}
printTimeElapsedWhenRunningCode(title: "s1()") {
let startingValue = Int(("A" as UnicodeScalar).value) // 65
for i in 0 ..< 256 {
print(Character(UnicodeScalar(i + startingValue)!))
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170409/a5cfa497/attachment.html>
More information about the swift-users
mailing list