-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pascal #7
Labels
add-language
Suggests adding a language.
Comments
@cleberlr very interesting results thank you for sharing👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could I offer a Pascal version of this code? Using FreePascal 3.3 compiler is almost as fast than C version.
{$mode delphi}
program leibniz;
uses
Windows, Messages, SysUtils, Classes, DateUtils;
var
file_contents: String;
t0,t2: Int64;
i,rounds: Integer;
input_file: TextFile;
x,pi: Double;
Frequency: int64;
begin
// Read the file into a string
QueryPerformanceFrequency(Frequency);
AssignFile(input_file,'rounds.txt');
Reset(input_file);
Readln(input_file, file_contents);
CloseFile(input_file);
rounds := StrToInt(file_contents); // convert into an Integer
QueryPerformanceCounter(t0);
x := 1.0;
pi := 1.0;
for i := 2 to rounds + 1 do
begin
x:= x * -1;
pi:= pi + (x / (2.0 * i - 1.0));
end;
pi:= pi * 4;
QueryPerformanceCounter(t2);
Writeln(Format('%.16f',[pi]));
Writeln('time: '+Format('%.3f',[1000*(t2-t0)/Frequency])+' msec');
end.
If you want test a binary (that not use rounds.txt, only a fix value, 1000000), I uploaded an optimized binary in https://pixeldrain.com/u/jMFWXYIO
I ran some tests using the fastest binary that I could compile for my machine (Ryzen 7 1700)..
C -> 0.141ms
C++ -> 0.141ms
pascal -> 0.157ms
python -> 378.7ms
The text was updated successfully, but these errors were encountered: