tulik / pi-monte-carlo

Comparison of ANSI C, Golang and PHP7 efficiency on calculating PI approximation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PI Monte Carlo method of successive approximations

ANSI C solution build, run and timing:

gcc -o pi-monte-carlo pi-monte-carlo.c
time ./pi-monte-carlo 100000000

Result

# of trials= 100000000 , estimate of pi is 3.14165

real	0m3.829s
user	0m3.680s
sys	0m0.008s

### Golang solution run and timing: `time go run pi-monte-carlo.go 10000000`
### Result
# of trials= 100000000 , estimate of pi is 3.14184392

real 0m4.549s user 0m4.356s sys 0m0.036s


PHP solution run and timing:

time php pi-monte-carlo.php 10000000

Result

# of trials= 100000000 , estimate of pi is 3.142

real	0m41.841s
user	0m39.164s
sys	0m0.024s

About

Comparison of ANSI C, Golang and PHP7 efficiency on calculating PI approximation.


Languages

Language:C 39.0%Language:Go 34.6%Language:PHP 26.5%