This program uses a random uniform distribution of doubles between 0 and 1 to estimate pi based on how many points are located in a radius of 1 compared to a square of 1 by 1. Written to compare the speed of execution across all kinds of different languages.
Test run on iMac 2017, Intel i7-7700K on macOS 11.4:
% ./piC
Number of test cases: 10000000
Pi estimation: 3.141878
Time taken: 0.515146 seconds
Let's see how many we can implement!
- C
- C++
- Swift
- Python
- JavaScript
- TypeScript
- C#
- Java
- More!
- Would love to see this program run on the GPU for a massive speed increase!
- The output of the program should match the example above.
- Add instructions for running it in the new language, in a similar format to the previous README entries
- Follow the same calculation of estimating pi across all languages. This respository is designed to test execution speed with the only independent variable being the language.
- Feel free to give constructive criticism in improving all aspects of this repository and testing the efficiency of the code in terms of speed
When running the program, it will ask for a number of test cases. The more you enter the more accurate the pi estimation will be, and the longer it will take to execute.
./runall.sh
If you want to specify your own number of test cases, simply put the number as a parameter to the script:
./runall.sh 1000000
gcc -o piC pi.c
then
./piC
g++ -o piCpp pi.c
then
./piCpp
First check that you have Swift installed with
swift --version
It should be installed if you have Xcode installed. Then you can run with
swift pi.swift
this will build and run in one command.
First check that you have Python installed with
python --version
Then run with
python pi.py
First check that you have Javascript installed with
node -v
Then run with
node pi.js