Delphi测试取商除操作符DIV速度控制台程序

Delphi测试取商除操作符DIV控制台颈椎枕速度程序,欢迎加入Delphi开发局QQ群:32422310

program DivVsMult;

{$APPTYPE CONSOLE}
uses
  SysUtils,
  Windows;
var
  Start,Stop, Start2, Stop2, Freq:int64;
  i : integer;
  t : real;
  CpuSpeed : integer;
begin
  { TODO -oUser -cConsole Main : Insert code here }
  { Cpu Speed fastes cpu = 1 slower => 10
    it's just to determin the number of time to do the loop
    Maxint div CpuSpeed is calculated }
  if ParamCount = 1 then
    CpuSpeed := StrToIntDef(ParamStr(1),1)
  else
    CpuSpeed := 10;
  Writeln('Simple Number division:');
  Writeln('Calculating');
  QueryPerformanceFrequency(freq);
  QueryPerformanceCounter(Start);
  for i:=0 to MaxInt div  CpuSpeed do
    t := i * (1/100);
  QueryPerformanceCounter(Stop);
  Writeln(Format('First Pass Result:  %f',[t]));
   { This is needed because the compiler would optimize,
     and would notice the result of the loop isn't used at all,
     so therefor the result is useless.. so depending on the compiler, it will
     choose what to do with it, this disables that optimization   }
  QueryPerformanceCounter(Start2);
  for i:=0 to MaxInt div CpuSpeed do
    t := i * (1/100);
  QueryPerformanceCounter(Stop2);
  Writeln(Format('Second Pass Result: %15.6f',[t]));
   { This is needed because the compiler would optimize,
     and would notice the result of the loop isn't used at all,
     so therefor the result is useless.. so depending on the compiler, it will
     choose what to do with it, this disables that optimization   }
  Writeln('Done, Results:');
  Writeln(Format('/ 100  Time:  %6.4f seconds'+#13#10+
          '/ 100  Clock: %d ticks'+#13#10+
          '* 0.01 Time:  %6.4f seconds'+#13#10+
          '* 0.01 Clock: %d ticks',
          [(Stop-Start) / freq,
          (Stop-Start),
          (Stop2-Start2) / freq,
          (Stop2-Start2)]));
  Writeln;
  Writeln('Odd Number division:');
  QueryPerformanceCounter(Start);
  for i:=0 to high(i) div CpuSpeed do
    t := i / 556;
  QueryPerformanceCounter(Stop);
  Writeln(Format('First Pass Result:  %15.6f',[t]));
   { This is needed because the compiler would optimize,
     and would notice the result of the loop isn't used at all,
     so therefor the result is useless.. so depending on the compiler, it will
     choose what to do with it, this disables that optimization   }
  QueryPerformanceCounter(Start2);
  for i:=0 to high(i) div CpuSpeed do
    t := i * (1/556);
  QueryPerformanceCounter(Stop2);
  Writeln(Format('Second Pass Result: %15.6f',[t]));
  Writeln(Format('/ 556     Time:  %6.4f seconds'+#13#10+
          '/ 556     Clock: %d ticks'+#13#10+
          '* (1/556) Time:  %6.4f seconds'+#13#10+
          '* (1/556) Clock: %d ticks',
          [(Stop-Start) / freq,
          (Stop-Start),
          (Stop2-Start2) / freq,
          (Stop2-Start2)]));
  Writeln(Format('  (1/556) = %15.14f (approximate)',[1/556]));
//  Readln;
end.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值