用superpi、tinypi、tpi等工具计算圆周率的比较

无意中发现,测试CPU性能的super pi程序开源了。

https://github.com/Fibonacci43/SuperPI/archive/refs/heads/main.zip

在windows中用mingw64 gcc编译

复制代码
C:\d>set path=C:\WINDOWS\system32;C:\WINDOWS;C:\d\mingw64\bin;C:\d\pypy

C:\d>cd SuperPI-main

C:\d\SuperPI-main>gcc -O -funroll-loops -fomit-frame-pointer pi_fftcs.c fftsg_h.c -lm -o pi_css5



C:\d\SuperPI-main>pi_css5
Calculation of PI using FFT and AGM, ver. LG1.1.2-MP1.5.2a.memsave

Usage: pi_css5 digits

Number of digits of pi to calculate?
1
initializing...
nfft= 2
radix= 10000
error_margin= 1.0747e-07
calculating 8 digits of PI...
AGM iteration
precision= 48: 0.00 sec
writing pi8.txt...
0.00 sec. (real time)
Hit RETURN to exit.


C:\d\SuperPI-main>pi_css5
Calculation of PI using FFT and AGM, ver. LG1.1.2-MP1.5.2a.memsave

Usage: pi_css5 digits

Number of digits of pi to calculate?
1000000
initializing...
nfft= 262144
radix= 10000
error_margin= 0.00611182
calculating 1048576 digits of PI...
AGM iteration
precision= 48: 0.06 sec
precision= 80: 0.06 sec
precision= 176: 0.06 sec
precision= 352: 0.06 sec
precision= 688: 0.06 sec
precision= 1392: 0.06 sec
precision= 2784: 0.06 sec
precision= 5584: 0.06 sec
precision= 11168: 0.06 sec
precision= 22336: 0.06 sec
precision= 44688: 0.06 sec
precision= 89408: 0.06 sec
precision= 178816: 0.06 sec
precision= 357648: 0.06 sec
precision= 715312: 0.06 sec
precision= 1430640: 0.06 sec
writing pi1048576.txt...
1.05 sec. (real time)
Hit RETURN to exit.


C:\d\SuperPI-main>pi_css5
Calculation of PI using FFT and AGM, ver. LG1.1.2-MP1.5.2a.memsave

Usage: pi_css5 digits

Number of digits of pi to calculate?
10000000
initializing...
nfft= 4194304
radix= 10000
error_margin= 0.136439
calculating 16777216 digits of PI...
AGM iteration
precision= 48: 1.02 sec
precision= 80: 1.02 sec
precision= 176: 1.02 sec
precision= 352: 1.02 sec
precision= 688: 1.02 sec
precision= 1392: 1.02 sec
precision= 2784: 1.02 sec
precision= 5584: 1.02 sec
precision= 11168: 1.02 sec
precision= 22336: 1.02 sec
precision= 44688: 1.02 sec
precision= 89408: 1.02 sec
precision= 178816: 1.02 sec
precision= 357648: 1.02 sec
precision= 715312: 1.02 sec
precision= 1430640: 1.02 sec
precision= 2861280: 1.02 sec
precision= 5722592: 1.02 sec
precision= 11445200: 1.02 sec
precision= 22890416: 1.03 sec
writing pi16777216.txt...
23.32 sec. (real time)
Hit RETURN to exit.

100万和1600万的执行结果比tinycc作者的tinypi还要快。

复制代码
C:\d\SuperPI-main>

https://bellard.org/pi/tinypi/

https://bellard.org/pi/tinypi/tinypi-2024-11-04.tar.gz

C:\d\SuperPI-main>gcc -O2 tinypi.c -o tinypi

C:\d\SuperPI-main>..\timer64 tinypi 1e6 pi_1e6.txt


Kernel  Time =     0.046 =    3%
User    Time =     1.328 =   93%
Process Time =     1.375 =   97%    Virtual  Memory =     10 MB
Global  Time =     1.415 =  100%    Physical Memory =     13 MB

C:\d\SuperPI-main>..\timer64 tinypi 1e7 pi_1e7.txt


Kernel  Time =     0.453 =    1%
User    Time =    24.000 =   97%
Process Time =    24.453 =   99%    Virtual  Memory =    100 MB
Global  Time =    24.503 =  100%    Physical Memory =    103 MB

但是不如bellard没有开源,只提供二进制文件的tpi快。

https://bellard.org/pi/pi2700e9/tpi-0.9.3-win.zip

https://bellard.org/pi/pi2700e9/tpi-0.9-linux.tar.gz

复制代码
C:\d\SuperPI-main>..\timer64 tpi -o pi.txt 10M
Using 12.6GiB of RAM
Computation to 10000000 digits, formula=Chudnovsky
Output file=pi.txt, format=txt, binary result size=4.15MB
Binary Splitting
Depth=20
  mem   max  disk   max operation                       compl lv
55.5M 55.5M     0     0 completed                      100.0%  0
  time = 1.955 s
Compute P, Q
43.5M 55.5M     0     0 completed
  time = 0.028 s
Division
61.5M 61.5M     0     0 completed
  time = 0.187 s
Sqrt
54.4M 61.5M     0     0 completed
  time = 0.120 s
Final multiplication
85.3M 85.3M     0     0 completed
  time = 0.088 s
Total time (binary result) = 2.378 s
Base conversion
56.4M 85.3M     0     0 completed
  time = 0.336 s
Total time (base 10 result) = 2.714 s
Writing result to 'pi.txt'


Kernel  Time =     0.328 =   11%
User    Time =     2.453 =   86%
Process Time =     2.781 =   98%    Virtual  Memory =     87 MB
Global  Time =     2.836 =  100%    Physical Memory =     91 MB


C:\d\SuperPI-main>..\timer64 tpi -T 4 -o pi4.txt 10M
Using 12.6GiB of RAM
Computation to 10000000 digits, formula=Chudnovsky
Output file=pi4.txt, format=txt, binary result size=4.15MB
Binary Splitting
Depth=20, thread_level=0
  mem   max  disk   max operation                       compl lv
55.8M 55.8M     0     0 completed                        0.0%  0
  time = 0.641 s
Compute P, Q
43.2M 55.8M     0     0 completed
  time = 0.015 s
Division
61.7M 61.7M     0     0 completed
  time = 0.097 s
Sqrt
54.7M 61.7M     0     0 completed
  time = 0.065 s
Final multiplication
85.8M 85.8M     0     0 completed
  time = 0.038 s
Total time (binary result) = 0.857 s
Base conversion
56.7M 85.8M     0     0 completed
  time = 0.281 s
Total time (base 10 result) = 1.138 s
Writing result to 'pi4.txt'


Kernel  Time =     0.234 =   19%
User    Time =     2.484 =  201%
Process Time =     2.718 =  220%    Virtual  Memory =     90 MB
Global  Time =     1.230 =  100%    Physical Memory =     94 MB

tpi还支持并行计算。

相关推荐
a187927218311 小时前
【算法】链表(二):链表上的双指针——变速、异链与定距,和一份路程账本
数据结构·算法·leetcode·链表·go·指针·环形链表
2601_958352902 小时前
还要写 AEC 算法?0 代码 + 6 个引脚,F-18 让通话清晰度提升 300%
人工智能·算法·降噪消回音
happyprince2 小时前
03-regmix-深刻观-哲学与升华
算法
一路向阳~负责的男人2 小时前
运动控制算法收录
算法
czt_java2 小时前
5个核心位运算公式
算法
Doubbbbbbble云3 小时前
区间合并问题的常见算法模式与优化思路4
java·数据结构·算法
David猪大卫3 小时前
【C++修炼】哈希表的实现
数据结构·c++·笔记·学习·算法·哈希算法·散列表
零依赖极客3 小时前
Day 8·1 自注意力机制:Q·K^T/softmax/V的在线计算
c语言·arm开发·人工智能·llama
hahaha60164 小时前
HLS高层次综合设计技巧--数组
开发语言·嵌入式硬件·算法·fpga开发