用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还支持并行计算。

相关推荐
希望我万事顺遂12 小时前
力扣hot100-滑动窗口最大值
数据结构·算法·leetcode
꧁细听勿语情꧂13 小时前
二叉树余题,排序、直接插入排序、希尔排序
c语言·开发语言·数据结构·算法
是main不是漫13 小时前
【双指针|LeetCode1089 复写零】巧用逆向思路,破解原地覆盖陷阱
数据结构·算法·leetcode
是main不是漫13 小时前
【C++——类和对象(上)】筑基篇:以封装奠定面向对象之基
c语言·开发语言·c++
专注仿真1 天前
知识问答模型用到的算法集详解及代码实例
python·算法·代码·大模型训练·控制算法
罗西的思考1 天前
【轻量化复刻大模型 / KIMI K3】AttnRes 模块交互式演示
人工智能·算法·机器学习
好悬给我拽开线1 天前
ZILOT 论文解析
算法
饮水桶_T1 天前
JAVA IO流笔记
开发语言·数据结构·算法
星夜离尘561 天前
MATLAB 离散数据分箱:半开区间、末端点与计数、加权和、平均
算法·matlab
Pniubi1 天前
力扣76.最小覆盖子串
算法·leetcode·职场和发展