This post was last edited by tobot on 2021-8-11 10:33
We know that pi is an infinite non-repeating decimal (also called an irrational number). Sometimes we can use the time to calculate the value of pi to measure the quality of the CPU . Seeing that netizen @MianJi likes to compare this evaluation board with the Raspberry Pi 3B , I'd like to join in the fun. I have a ready-made Raspberry Pi 3B and 4B , but they are both 1G versions. Their performance may not be lower than that of the i.MX8M Mini , but the difference in memory may make them suffer a little in the evaluation results.
In the original ecosystem of Mil MYS-8MMQ6-8E2D-180-C , there are only python2 and python3 . Even the most commonly used gcc is not found. There is nothing like java , ruby , go , php ... However, there is bc in the shell , you can try it, then let's mainly use python for comparison.
Here are several calculation methods:
1. Power series expansion of inverse trigonometric functions
We know that π is a very special value in trigonometric functions , such as sin( π /2)=1 , tan( π /4)=1 , etc. Therefore, we can use the power series expansion of inverse sine or inverse tangent to calculate the value of pi .
For example,
In the inverse cotangent formula, let x = 1 , then arctan(x) = π /4 , expand and organize
Compilation Tools
|
Order
|
Cycle times
|
Raspberry Pi 3 B
|
Raspberry Pi 4 B (1G)
|
MYS-8MMX
|
shell
|
time bash trigonometric.sh
|
10000
|
|
|
|
bc
|
time bc -q trigonometric.bc
|
1 0000000
|
|
|
|
python2
|
time python 2 trigonometric.py
|
5 0000000
|
|
|
|
python3
|
time python 3 trigonometric.py
|
5 0000000
|
|
|
|
- Grid method
The distance from a point inside a circle to the center of the circle is less than the radius of the circle. So divide 1/4 of the circle into n*n grids, count how many grids fall inside the circle, divide it by the total number of grids, and multiply by 4 , and you can calculate the value of π.
Compilation Tools
|
Order
|
Cycle times
|
Raspberry Pi 3 B
|
Raspberry Pi 4 B (1G)
|
MYS-8MMX
|
shell
|
time bash grid.sh
|
10000
|
|
|
|
bc
|
time bc -q grid.bc
|
10000000
|
|
|
|
python2
|
time python 2 grid.py
|
5 0000000
|
|
|
|
python3
|
time python 3 grid.py
|
5 0000000
|
|
|
|
- Multiplication
Pi can be calculated using
.
Compilation Tools
|
Order
|
Cycle times
|
Raspberry Pi 3B
|
Raspberry Pi 4 B (1G)
|
MYS-8MMX
|
shell
|
time bash multipli.sh
|
10000
|
|
|
|
bc
|
time bc -q multipli.bc
|
5000000
|
|
|
|
python2
|
time python 2 multipli.py
|
50000000
|
|
|
|
python3
|
time python 3 multipli.py
|
50000000
|
|
|
|
- Monte Carlo method (random number method)
The method of estimating parameters using the results obtained through probability experiments is called the Monte Carlo method .
We can randomly pick a point in the square and the probability that it is in its inscribed circle is π /4 . We can use this to calculate pi.
Compilation Tools
|
Order
|
Cycle times
|
Raspberry Pi 3B
|
Raspberry Pi 4 B (1G)
|
MYS-8MMX
|
shell
|
time bash rand.sh
|
1000000
|
|
|
|
python2
|
time python 2 rand.py
|
50000000
|
|
|
|
python3
|
time python 3 rand.py
|
50000000
|
|
|
|
Judging from the above results, the performance of NXP 's i.MX8M Mini is slightly lower than Broadcom BCM2711 , but higher than Broadcom BCM2837 .
Why does memory overflow occur?