<div dir="ltr"><p style="box-sizing:border-box;margin:0px;padding:0px;color:rgb(61,60,64);font-family:slack-lato,applelogo,sans-serif;font-size:15px;font-variant-ligatures:none;white-space:pre-wrap">How do I append character A-Z by integer into CChar and benchmark timing how fast it’s append compare to UInt8? </p><p style="box-sizing:border-box;margin:0px;padding:0px;color:rgb(61,60,64);font-family:slack-lato,applelogo,sans-serif;font-size:15px;font-variant-ligatures:none;white-space:pre-wrap"><br></p><p style="box-sizing:border-box;margin:0px;padding:0px;color:rgb(61,60,64);font-variant-ligatures:none;white-space:pre-wrap"><font face="monospace, monospace">var tmp: [CChar] = [0,0]</font></p><p style="box-sizing:border-box;margin:0px;padding:0px;color:rgb(61,60,64);font-variant-ligatures:none;white-space:pre-wrap"><font face="monospace, monospace">for var i in 0...256 {</font></p><p style="box-sizing:border-box;margin:0px;padding:0px;color:rgb(61,60,64);font-variant-ligatures:none;white-space:pre-wrap"><font face="monospace, monospace"> tmp[0] = 100</font></p><p style="box-sizing:border-box;margin:0px;padding:0px;color:rgb(61,60,64);font-variant-ligatures:none;white-space:pre-wrap"><font face="monospace, monospace">}</font></p><p style="box-sizing:border-box;margin:0px;padding:0px;color:rgb(61,60,64);font-variant-ligatures:none;white-space:pre-wrap"><font face="monospace, monospace">print(String(cString: &tmp))</font></p><p style="box-sizing:border-box;margin:0px;padding:0px;color:rgb(61,60,64);font-family:slack-lato,applelogo,sans-serif;font-size:15px;font-variant-ligatures:none;white-space:pre-wrap"><br></p><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 9, 2017 at 3:17 AM, Proyb P <span dir="ltr"><<a href="mailto:proyb6@gmail.com" target="_blank">proyb6@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Agree, in some case, I seem to find Cchar is really shine at 10x faster than Python from A to Z, 1000x faster than normal Swift? Not sure if there was flaw in the time measurement.<div class="HOEnZb"><div class="h5"><br><br>On Sunday, 9 April 2017, Rien <<a href="mailto:Rien@balancingrock.nl" target="_blank">Rien@balancingrock.nl</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Server-side is usually UTF-8 (not always), so often you don’t really need strings.<br>
As an aside, time measurements are difficult, especially when IO is involved there may be thread switches or locks.<br>
<br>
I have written some parsers (UTF-8 based) and not yet encountered performance problems. (though faster is always better)<br>
<br>
Regards,<br>
Rien<br>
<br>
Site: <a href="http://balancingrock.nl" target="_blank">http://balancingrock.nl</a><br>
Blog: <a href="http://swiftrien.blogspot.com" target="_blank">http://swiftrien.blogspot.com</a><br>
Github: <a href="http://github.com/Balancingrock" target="_blank">http://github.com/Balancingroc<wbr>k</a><br>
Project: <a href="http://swiftfire.nl" target="_blank">http://swiftfire.nl</a> - A server for websites build in Swift<br>
<br>
<br>
<br>
<br>
<br>
<br>
> On 08 Apr 2017, at 18:19, Proyb P via swift-users <<a>swift-users@swift.org</a>> wrote:<br>
><br>
> I have found this took about 0.001s to print 256 characters<br>
> 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.<br>
> <a href="https://gist.github.com/anonymous/18e372e8d0173e77b5c405920d4d3080" target="_blank">https://gist.github.com/anonym<wbr>ous/18e372e8d0173e77b5c405920d<wbr>4d3080</a><br>
><br>
> 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?<br>
><br>
> import Foundation<br>
> var display: String = ""<br>
><br>
> func printTimeElapsedWhenRunningCod<wbr>e(title: String, operation: ()->()) {<br>
> let startTime = CFAbsoluteTimeGetCurrent()<br>
> operation()<br>
> let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime<br>
> print("Time elapsed for \(title): \(timeElapsed) s")<br>
> }<br>
><br>
> <wbr>printTimeElapsedWhenRunningCod<wbr>e(title: "s1()") {<br>
> let startingValue = Int(("A" as UnicodeScalar).value) // 65<br>
> for i in 0 ..< 256 {<br>
> print(Character(<wbr>UnicodeScalar(i + startingValue)!))<br>
> }<br>
> }<br>
> ______________________________<wbr>_________________<br>
> swift-users mailing list<br>
> <a>swift-users@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
<br>
</blockquote>
</div></div></blockquote></div><br></div></div>