3 ms·
This test is rather misleading. For instance, I decided to rewrite this same procedure in Swift. I was stunned to find out that at first the speed was almost 4
by x0054 11y ago
This test is rather misleading. For instance, I decided to rewrite this same procedure in Swift. I was stunned to find out that at first the speed was almost 4 times slower. The C program took 34 seconds to run to 67108864 while Swift took 2:11 minutes.
However, after swapping out the Float only capable square root from Swift Foundation for the C sqrt function, leaving the rest of the code identical, the execution time on the Swift code went down to 35 seconds, basically identical.
I have to wonder if Python, Ruby, and PHP just have a Float only capable square root function, or handle numbers with much higher precision than necessary by the test.
- caf 11y agoThe C sqrt function is double sqrt(double)
- x0054 11y agoHmm, I can see that too now, though I am passing into it a CInt, and getting back a CInt. Is it just converting the Int to Double internally and shooting back a Double which is converted to CInt? If so, why do you think it's so much faster?