<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: &amp;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">&lt;<a href="mailto:proyb6@gmail.com" target="_blank">proyb6@gmail.com</a>&gt;</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 &lt;<a href="mailto:Rien@balancingrock.nl" target="_blank">Rien@balancingrock.nl</a>&gt; 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>
&gt; On 08 Apr 2017, at 18:19, Proyb P via swift-users &lt;<a>swift-users@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; I have found this took about 0.001s to print 256 characters<br>
&gt; 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>
&gt; <a href="https://gist.github.com/anonymous/18e372e8d0173e77b5c405920d4d3080" target="_blank">https://gist.github.com/anonym<wbr>ous/18e372e8d0173e77b5c405920d<wbr>4d3080</a><br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; import Foundation<br>
&gt; var display: String = &quot;&quot;<br>
&gt;<br>
&gt;     func printTimeElapsedWhenRunningCod<wbr>e(title: String, operation: ()-&gt;()) {<br>
&gt;         let startTime = CFAbsoluteTimeGetCurrent()<br>
&gt;         operation()<br>
&gt;         let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime<br>
&gt;         print(&quot;Time elapsed for \(title): \(timeElapsed) s&quot;)<br>
&gt;     }<br>
&gt;<br>
&gt;     <wbr>printTimeElapsedWhenRunningCod<wbr>e(title: &quot;s1()&quot;) {<br>
&gt; let startingValue = Int((&quot;A&quot; as UnicodeScalar).value) // 65<br>
&gt; for i in 0 ..&lt; 256 {<br>
&gt;     print(Character(<wbr>UnicodeScalar(i + startingValue)!))<br>
&gt; }<br>
&gt; }<br>
&gt; ______________________________<wbr>_________________<br>
&gt; swift-users mailing list<br>
&gt; <a>swift-users@swift.org</a><br>
&gt; <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>