DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: haibei
今日帖子: 8
在线用户: 10
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 ay1116 (Beginner) ★☆☆☆☆ -
盒子活跃会员
2023/9/13 12:55:15
标题:
闲来无事,测了Lazarus的32位和64位性能,和Delphi对比了一下 浏览:560
加入我的收藏
楼主: program pi;

{$mode objfpc}{$H+}





  function ComputePi(NumDigits: Integer): string;
  var
    A: array of LongInt;
    I, J, K, P, Q, X, Nines, Predigit: Integer;
    PiLength: Integer;
  begin
    SetLength(A, 10*NumDigits div 3);
    SetLength(Result, NumDigits+1);
    PiLength := 1;
    for I := Low(A) to High(A) do
      A[I] := 2;
    Nines := 0;
    Predigit := 0;
    for J := 0 to NumDigits-1 do
    begin
      Q := 0;
      P := 2 * High(A) + 1;
      for I := High(A) downto Low(A) do
      begin
        X := 10*A[I] + Q*(I+1);
        A[I] := X mod P;
        Q := X div P;
        P := P - 2;
      end;
      A[Low(A)] := Q mod 10;
      Q := Q div 10;
      if Q = 9 then
        Inc(Nines)
      else if Q = 10 then
      begin
        Result[PiLength] := Chr(Predigit + 1 + Ord('0'));
        for K := 1 to Nines do
          Result[PiLength+K] := '0';
        PiLength := PiLength + Nines + 1;
        Predigit := 0;
        Nines := 0;
      end
      else
      begin
        Result[PiLength] := Chr(Predigit + Ord('0'));
        Predigit := Q;
        for K := 1 to Nines do
          Result[PiLength+K] := '9';
        PiLength := PiLength + Nines + 1;
        Nines := 0;
      end;
    end;
    Result[PiLength] := Chr(Predigit + Ord('0'));
  end;

  var
    NumDigits: Integer;
    Code: Integer;
    F: TextFile;
  begin
    if ParamCount = 0 then
      WriteLn('usage: pi #DIGITS [FILE]')
    else
    begin
      Val(ParamStr(1), NumDigits, Code);
      if Code <> 0 then
      begin
        WriteLn('Invalid # digits: ', ParamStr(1));
        Halt(1);
      end;

      if ParamCount > 1 then
      begin
        AssignFile(F, ParamStr(2));
        Rewrite(F);
        WriteLn(F, ComputePi(NumDigits));
        CloseFile(F);
      end
      else
        WriteLn(ComputePi(NumDigits));
    end;
  end.


lazarus 2.2.4
FPC 3.2.2
计算PI的位数需要的时间,结果是:

10000位
Delphi-7.exe 2907
pi-lazarus-x86.exe 3203
pi-lazarus-x64.exe 5672
delphixe8-x86.exe 2890
delphixe8-x64.exe 2891


20000位
delphixe8-x64.exe 12578
delphixe8-x86.exe 11688
Delphi-7.exe 12781
pi-lazarus-x86.exe 14563
pi-lazarus-x64.exe 25297
感觉lazarus的64位没优化好样。。
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/9/13 13:06:39
1楼: from Embarcadero Blog
by Jim McKeeth


Calculating Pi in Delphi for Pi Day 2023
https://www.google.com/amp/s/blogs.embarcadero.com/calculating-pi-in-delphi-for-pi-day-2023/amp/

Google recently calculated 100 Trillion digits of Pi. It took 157 days, 23 hours, 31 minutes and 7.651 seconds on a 128 vCPUs with 864 GB RAM, 515 TB storage, and 82 PB of I/O. This was an opportunity to show off their cloud computing infrastructure. So the practical among us would just download the digits we need (as long as it is less than 100 trillion).


on github sources
https://gist.github.com/jimmckeeth/88d76a4ecee150e6cdcdf200b5c473a1

BigIntegers by Rudy Velthuis
https://github.com/rvelthuis/DelphiBigNumbers
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行125毫秒 RSS