Jump to content

Dalibor31

Members
  • Content Count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. Dalibor31

    Strange Benchmark Results; Am I Missing Something?

    program Benchmark; {$APPTYPE CONSOLE} uses SysUtils, DateUtils; var StartTime, EndTime: TDateTime; Total: Int64; NumOfIterations3, NumOfIterations5, NumOfIterations15: Int64; Sum3, Sum5, Sum15: Int64; Duration: Double; Key: Char; begin // Start measuring time StartTime := Now; NumOfIterations3 := 1000000000 div 3; NumOfIterations5 := 1000000000 div 5; NumOfIterations15 := 1000000000 div 15; Sum3 := NumOfIterations3 * (NumOfIterations3 + 1) div 2 * 3; Sum5 := NumOfIterations5 * (NumOfIterations5 + 1) div 2 * 5; Sum15 := NumOfIterations15 * (NumOfIterations15 + 1) div 2 * 15; Total := Sum3 + Sum5 - Sum15; // Stop measuring time EndTime := Now; Duration := SecondsBetween(EndTime, StartTime); Writeln('Total: ', Total); Writeln('Time taken: ', Duration:0:6, ' seconds'); Write('Press any key to exit'); Readln(Key); end. What about this code optimization?
×