Skip to content

Comment on Cote D'Azur – Performance of pi calculation in multiple languages (2013)

Comments

The C code is quite unoptimised as well...

Running the original on my machine (compiled with VS2013) takes 3.75 seconds. Changing the comparison to (x * x + y * y) <= 1.0 (no need for the sqrt since we are comparing with 1!) takes the runtime down to 2.87 seconds. Switching the accumulation from a branch to hits+=in_circle(r1, r2) further reduces it to 2.43 seconds.

To be fair, all of the codes use sqrt, so if you're going to do clever hand-optimizing in the C version, then you should do the same in the other ones too.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.