Hacker News new | ask | show | jobs
by MattPearce 4259 days ago
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.

1 comments

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.