bdiv.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. { %OPT=-O2 }
  2. program bdiv;
  3. {$mode objfpc}{$H+}
  4. uses
  5. SysUtils;
  6. { Utility functions }
  7. function GetRealTime(const st: TSystemTime): Real;
  8. begin
  9. Result := st.Hour*3600.0 + st.Minute*60.0 + st.Second + st.MilliSecond/1000.0;
  10. end;
  11. {$push}
  12. {$warn 5057 off}
  13. function GetRealTime : Real;
  14. var
  15. st:TSystemTime;
  16. begin
  17. GetLocalTime(st);
  18. result:=GetRealTime(st);
  19. end;
  20. {$pop}
  21. const
  22. {$if defined(cpuarm) or defined(cpuavr) or defined(cpui8086) or defined(cpum68k) or defined(cpumips) or defined(cpuz80) or defined(cpuriscv32)}
  23. {$define slowcpu}
  24. {$endif}
  25. {$ifdef slowcpu}
  26. ITERATIONS = 32768;
  27. {$else slowcpu}
  28. ITERATIONS = 524288;
  29. {$endif slowcpu}
  30. INTERNAL_LOOPS = 64;
  31. { TTestAncestor }
  32. type
  33. TTestAncestor = class
  34. private
  35. FStartTime: Real;
  36. FEndTime: Real;
  37. FAvgTime: Real;
  38. procedure SetStartTime;
  39. procedure SetEndTime;
  40. protected
  41. procedure DoTestIteration(Iteration: Integer); virtual; abstract;
  42. public
  43. constructor Create; virtual;
  44. destructor Destroy; override;
  45. procedure Run;
  46. function TestTitle: shortstring; virtual; abstract;
  47. function WriteResults: Boolean; virtual; abstract;
  48. property RunTime: Real read FAvgTime;
  49. end;
  50. TTestClass = class of TTestAncestor;
  51. TUInt16DivTest = class(TTestAncestor)
  52. protected
  53. FInputArray: array[$00..$FF] of Word;
  54. FResultArray: array[$00..$FF] of Word;
  55. function GetDivisor: Word; virtual; abstract;
  56. function DoVariableDiv(Numerator: Word): Word; inline;
  57. public
  58. function WriteResults: Boolean; override;
  59. end;
  60. TUInt16ModTest = class(TUInt16DivTest)
  61. protected
  62. function DoVariableMod(Numerator: Word): Word; inline;
  63. public
  64. function WriteResults: Boolean; override;
  65. end;
  66. TUInt32DivTest = class(TTestAncestor)
  67. protected
  68. FInputArray: array[$00..$FF] of Cardinal;
  69. FResultArray: array[$00..$FF] of Cardinal;
  70. function GetDivisor: Cardinal; virtual; abstract;
  71. function DoVariableDiv(Numerator: Cardinal): Cardinal; inline;
  72. public
  73. function WriteResults: Boolean; override;
  74. end;
  75. TUInt32ModTest = class(TUInt32DivTest)
  76. protected
  77. function DoVariableMod(Numerator: Cardinal): Cardinal; inline;
  78. public
  79. function WriteResults: Boolean; override;
  80. end;
  81. TSInt32DivTest = class(TTestAncestor)
  82. protected
  83. FInputArray: array[$00..$FF] of Integer;
  84. FResultArray: array[$00..$FF] of Integer;
  85. function GetDivisor: Integer; virtual; abstract;
  86. function DoVariableDiv(Numerator: Integer): Integer; inline;
  87. public
  88. function WriteResults: Boolean; override;
  89. end;
  90. TSInt32ModTest = class(TSInt32DivTest)
  91. protected
  92. function DoVariableMod(Numerator: Integer): Integer; inline;
  93. public
  94. function WriteResults: Boolean; override;
  95. end;
  96. TUInt64DivTest = class(TTestAncestor)
  97. protected
  98. FInputArray: array[$00..$FF] of QWord;
  99. FResultArray: array[$00..$FF] of QWord;
  100. function GetDivisor: QWord; virtual; abstract;
  101. function DoVariableDiv(Numerator: QWord): QWord; inline;
  102. public
  103. function WriteResults: Boolean; override;
  104. end;
  105. TUInt64ModTest = class(TUInt64DivTest)
  106. protected
  107. function DoVariableMod(Numerator: QWord): QWord; inline;
  108. public
  109. function WriteResults: Boolean; override;
  110. end;
  111. TSInt64DivTest = class(TTestAncestor)
  112. protected
  113. FInputArray: array[$00..$FF] of Int64;
  114. FResultArray: array[$00..$FF] of Int64;
  115. function GetDivisor: Int64; virtual; abstract;
  116. function DoVariableDiv(Numerator: Int64): Int64; inline;
  117. public
  118. function WriteResults: Boolean; override;
  119. end;
  120. TSInt64ModTest = class(TSInt64DivTest)
  121. protected
  122. function DoVariableMod(Numerator: Int64): Int64; inline;
  123. public
  124. function WriteResults: Boolean; override;
  125. end;
  126. TUInt32ModCmpTest = class(TTestAncestor)
  127. protected
  128. FInputArray: array[$00..$FF] of Cardinal;
  129. FResultArray: array[$00..$FF] of Boolean;
  130. function GetDivisor: Cardinal; virtual; abstract;
  131. function DoMod0(Numerator: Cardinal): Boolean; inline;
  132. public
  133. function WriteResults: Boolean; override;
  134. end;
  135. TSInt32ModCmpTest = class(TTestAncestor)
  136. protected
  137. FInputArray: array[$00..$FF] of Integer;
  138. FResultArray: array[$00..$FF] of Boolean;
  139. function GetDivisor: Integer; virtual; abstract;
  140. function DoMod0(Numerator: Integer): Boolean; inline;
  141. public
  142. function WriteResults: Boolean; override;
  143. end;
  144. TUInt64ModCmpTest = class(TTestAncestor)
  145. protected
  146. FInputArray: array[$00..$FF] of QWord;
  147. FResultArray: array[$00..$FF] of Boolean;
  148. function GetDivisor: QWord; virtual; abstract;
  149. function DoMod0(Numerator: QWord): Boolean; inline;
  150. public
  151. function WriteResults: Boolean; override;
  152. end;
  153. TSInt64ModCmpTest = class(TTestAncestor)
  154. protected
  155. FInputArray: array[$00..$FF] of Int64;
  156. FResultArray: array[$00..$FF] of Boolean;
  157. function GetDivisor: Int64; virtual; abstract;
  158. function DoMod0(Numerator: Int64): Boolean; inline;
  159. public
  160. function WriteResults: Boolean; override;
  161. end;
  162. {$I bdiv_u16.inc}
  163. {$I bdiv_u32.inc}
  164. {$I bdiv_u64.inc}
  165. {$I bdiv_s32.inc}
  166. {$I bdiv_s64.inc}
  167. { TTestAncestor }
  168. constructor TTestAncestor.Create;
  169. begin
  170. FStartTime := 0;
  171. FEndTime := 0;
  172. FAvgTime := 0;
  173. end;
  174. destructor TTestAncestor.Destroy;
  175. begin
  176. inherited Destroy;
  177. end;
  178. procedure TTestAncestor.SetStartTime;
  179. begin
  180. FStartTime := GetRealTime();
  181. end;
  182. procedure TTestAncestor.SetEndTime;
  183. begin
  184. FEndTime := GetRealTime();
  185. if FEndTime < FStartTime then { Happens if the test runs past midnight }
  186. FEndTime := FEndTime + 86400.0;
  187. end;
  188. procedure TTestAncestor.Run;
  189. var
  190. X: Integer;
  191. begin
  192. SetStartTime;
  193. for X := 0 to ITERATIONS - 1 do
  194. DoTestIteration(X);
  195. SetEndTime;
  196. FAvgTime := FEndTime - FStartTime;
  197. end;
  198. { TUInt16DivTest }
  199. function TUInt16DivTest.DoVariableDiv(Numerator: Word): Word;
  200. begin
  201. Result := Numerator div GetDivisor;
  202. end;
  203. function TUInt16DivTest.WriteResults: Boolean;
  204. var
  205. X: Integer;
  206. Expected: Word;
  207. begin
  208. Result := True;
  209. for X := 0 to 255 do
  210. begin
  211. Expected := DoVariableDiv(FInputArray[X]);
  212. if FResultArray[X] <> Expected then
  213. begin
  214. WriteLn('FAIL - ', FInputArray[X], ' div ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  215. Result := False;
  216. Exit;
  217. end;
  218. end;
  219. end;
  220. { TUInt16ModTest }
  221. function TUInt16ModTest.DoVariableMod(Numerator: Word): Word;
  222. begin
  223. Result := Numerator mod GetDivisor;
  224. end;
  225. function TUInt16ModTest.WriteResults: Boolean;
  226. var
  227. X: Integer;
  228. Expected: Word;
  229. begin
  230. Result := True;
  231. for X := 0 to 255 do
  232. begin
  233. Expected := DoVariableMod(FInputArray[X]);
  234. if FResultArray[X] <> Expected then
  235. begin
  236. WriteLn('FAIL - ', FInputArray[X], ' mod ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  237. Result := False;
  238. Exit;
  239. end;
  240. end;
  241. end;
  242. { TUInt32DivTest }
  243. function TUInt32DivTest.DoVariableDiv(Numerator: Cardinal): Cardinal;
  244. begin
  245. Result := Numerator div GetDivisor;
  246. end;
  247. function TUInt32DivTest.WriteResults: Boolean;
  248. var
  249. X: Integer;
  250. Expected: Cardinal;
  251. begin
  252. Result := True;
  253. for X := 0 to 255 do
  254. begin
  255. Expected := DoVariableDiv(FInputArray[X]);
  256. if FResultArray[X] <> Expected then
  257. begin
  258. WriteLn('FAIL - ', FInputArray[X], ' div ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  259. Result := False;
  260. Exit;
  261. end;
  262. end;
  263. end;
  264. { TUInt32ModTest }
  265. function TUInt32ModTest.DoVariableMod(Numerator: Cardinal): Cardinal;
  266. begin
  267. Result := Numerator mod GetDivisor;
  268. end;
  269. function TUInt32ModTest.WriteResults: Boolean;
  270. var
  271. X: Integer;
  272. Expected: Cardinal;
  273. begin
  274. Result := True;
  275. for X := 0 to 255 do
  276. begin
  277. Expected := DoVariableMod(FInputArray[X]);
  278. if FResultArray[X] <> Expected then
  279. begin
  280. WriteLn('FAIL - ', FInputArray[X], ' mod ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  281. Result := False;
  282. Exit;
  283. end;
  284. end;
  285. end;
  286. { TSInt32DivTest }
  287. function TSInt32DivTest.DoVariableDiv(Numerator: Integer): Integer;
  288. begin
  289. Result := Numerator div GetDivisor;
  290. end;
  291. function TSInt32DivTest.WriteResults: Boolean;
  292. var
  293. X: Integer;
  294. Expected: Integer;
  295. begin
  296. Result := True;
  297. for X := 0 to 255 do
  298. begin
  299. Expected := DoVariableDiv(FInputArray[X]);
  300. if FResultArray[X] <> Expected then
  301. begin
  302. WriteLn('FAIL - ', FInputArray[X], ' div ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  303. Result := False;
  304. Exit;
  305. end;
  306. end;
  307. end;
  308. { TSInt32ModTest }
  309. function TSInt32ModTest.DoVariableMod(Numerator: Integer): Integer;
  310. begin
  311. Result := Numerator mod GetDivisor;
  312. end;
  313. function TSInt32ModTest.WriteResults: Boolean;
  314. var
  315. X: Integer;
  316. Expected: Integer;
  317. begin
  318. Result := True;
  319. for X := 0 to 255 do
  320. begin
  321. Expected := DoVariableMod(FInputArray[X]);
  322. if FResultArray[X] <> Expected then
  323. begin
  324. WriteLn('FAIL - ', FInputArray[X], ' mod ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  325. Result := False;
  326. Exit;
  327. end;
  328. end;
  329. end;
  330. { TUInt64DivTest }
  331. function TUInt64DivTest.DoVariableDiv(Numerator: QWord): QWord;
  332. begin
  333. Result := Numerator div GetDivisor;
  334. end;
  335. function TUInt64DivTest.WriteResults: Boolean;
  336. var
  337. X: Integer;
  338. Expected: QWord;
  339. begin
  340. Result := True;
  341. for X := 0 to 255 do
  342. begin
  343. Expected := DoVariableDiv(FInputArray[X]);
  344. if FResultArray[X] <> Expected then
  345. begin
  346. WriteLn('FAIL - ', FInputArray[X], ' div ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  347. Result := False;
  348. Exit;
  349. end;
  350. end;
  351. end;
  352. { TUInt64ModTest }
  353. function TUInt64ModTest.DoVariableMod(Numerator: QWord): QWord;
  354. begin
  355. Result := Numerator mod GetDivisor;
  356. end;
  357. function TUInt64ModTest.WriteResults: Boolean;
  358. var
  359. X: Integer;
  360. Expected: QWord;
  361. begin
  362. Result := True;
  363. for X := 0 to 255 do
  364. begin
  365. Expected := DoVariableMod(FInputArray[X]);
  366. if FResultArray[X] <> Expected then
  367. begin
  368. WriteLn('FAIL - ', FInputArray[X], ' mod ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  369. Result := False;
  370. Exit;
  371. end;
  372. end;
  373. end;
  374. { TSInt64DivTest }
  375. function TSInt64DivTest.DoVariableDiv(Numerator: Int64): Int64;
  376. begin
  377. Result := Numerator div GetDivisor;
  378. end;
  379. function TSInt64DivTest.WriteResults: Boolean;
  380. var
  381. X: Integer;
  382. Expected: Int64;
  383. begin
  384. Result := True;
  385. for X := 0 to 255 do
  386. begin
  387. Expected := DoVariableDiv(FInputArray[X]);
  388. if FResultArray[X] <> Expected then
  389. begin
  390. WriteLn('FAIL - ', FInputArray[X], ' div ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  391. Result := False;
  392. Exit;
  393. end;
  394. end;
  395. end;
  396. { TSInt64ModTest }
  397. function TSInt64ModTest.DoVariableMod(Numerator: Int64): Int64;
  398. begin
  399. Result := Numerator mod GetDivisor;
  400. end;
  401. function TSInt64ModTest.WriteResults: Boolean;
  402. var
  403. X: Integer;
  404. Expected: Int64;
  405. begin
  406. Result := True;
  407. for X := 0 to 255 do
  408. begin
  409. Expected := DoVariableMod(FInputArray[X]);
  410. if FResultArray[X] <> Expected then
  411. begin
  412. WriteLn('FAIL - ', FInputArray[X], ' mod ', GetDivisor, '; expected ', Expected, ' got ', FResultArray[X]);
  413. Result := False;
  414. Exit;
  415. end;
  416. end;
  417. end;
  418. { TSInt32ModCmpTest }
  419. function TSInt32ModCmpTest.DoMod0(Numerator: Integer): Boolean;
  420. begin
  421. Result := (Numerator mod GetDivisor) = 0;
  422. end;
  423. function TSInt32ModCmpTest.WriteResults: Boolean;
  424. var
  425. X: Integer;
  426. Expected: Boolean;
  427. begin
  428. Result := True;
  429. for X := 0 to 255 do
  430. begin
  431. Expected := DoMod0(FInputArray[X]);
  432. if FResultArray[X] <> Expected then
  433. begin
  434. WriteLn('FAIL - (', FInputArray[X], ' mod ', GetDivisor, ') = 0; expected ', Expected, ' got ', FResultArray[X]);
  435. Result := False;
  436. Exit;
  437. end;
  438. end;
  439. end;
  440. { TUInt32ModCmpTest }
  441. function TUInt32ModCmpTest.DoMod0(Numerator: Cardinal): Boolean;
  442. begin
  443. Result := (Numerator mod GetDivisor) = 0;
  444. end;
  445. function TUInt32ModCmpTest.WriteResults: Boolean;
  446. var
  447. X: Integer;
  448. Expected: Boolean;
  449. begin
  450. Result := True;
  451. for X := 0 to 255 do
  452. begin
  453. Expected := DoMod0(FInputArray[X]);
  454. if FResultArray[X] <> Expected then
  455. begin
  456. WriteLn('FAIL - (', FInputArray[X], ' mod ', GetDivisor, ') = 0; expected ', Expected, ' got ', FResultArray[X]);
  457. Result := False;
  458. Exit;
  459. end;
  460. end;
  461. end;
  462. { TSInt64ModCmpTest }
  463. function TSInt64ModCmpTest.DoMod0(Numerator: Int64): Boolean;
  464. begin
  465. Result := (Numerator mod GetDivisor) = 0;
  466. end;
  467. function TSInt64ModCmpTest.WriteResults: Boolean;
  468. var
  469. X: Integer;
  470. Expected: Boolean;
  471. begin
  472. Result := True;
  473. for X := 0 to 255 do
  474. begin
  475. Expected := DoMod0(FInputArray[X]);
  476. if FResultArray[X] <> Expected then
  477. begin
  478. WriteLn('FAIL - (', FInputArray[X], ' mod ', GetDivisor, ') = 0; expected ', Expected, ' got ', FResultArray[X]);
  479. Result := False;
  480. Exit;
  481. end;
  482. end;
  483. end;
  484. { TUInt64ModCmpTest }
  485. function TUInt64ModCmpTest.DoMod0(Numerator: QWord): Boolean;
  486. begin
  487. Result := (Numerator mod GetDivisor) = 0;
  488. end;
  489. function TUInt64ModCmpTest.WriteResults: Boolean;
  490. var
  491. X: Integer;
  492. Expected: Boolean;
  493. begin
  494. Result := True;
  495. for X := 0 to 255 do
  496. begin
  497. Expected := DoMod0(FInputArray[X]);
  498. if FResultArray[X] <> Expected then
  499. begin
  500. WriteLn('FAIL - (', FInputArray[X], ' mod ', GetDivisor, ') = 0; expected ', Expected, ' got ', FResultArray[X]);
  501. Result := False;
  502. Exit;
  503. end;
  504. end;
  505. end;
  506. { Main function }
  507. const
  508. TestClasses: array[0..84] of TTestClass = (
  509. TUInt16Bit1Test,
  510. TUInt16Bit1ModTest,
  511. TUInt16Bit2Test,
  512. TUInt16Bit2ModTest,
  513. TUInt16Bit3Test,
  514. TUInt16Bit3ModTest,
  515. TUInt16Bit7Test,
  516. TUInt16Bit7ModTest,
  517. TUInt16Bit10Test,
  518. TUInt16Bit10ModTest,
  519. TUInt16Bit100Test,
  520. TUInt16Bit100ModTest,
  521. TUInt16Bit1000Test,
  522. TUInt16Bit1000ModTest,
  523. TUInt32Bit1Test,
  524. TUInt32Bit1ModTest,
  525. TUInt32Bit2Test,
  526. TUInt32Bit2ModTest,
  527. TUInt32Bit3Test,
  528. TUInt32Bit3ModTest,
  529. TUInt32Bit7Test,
  530. TUInt32Bit7ModTest,
  531. TUInt32Bit10Test,
  532. TUInt32Bit10ModTest,
  533. TUInt32Bit100Test,
  534. TUInt32Bit100ModTest,
  535. TUInt32Bit1000Test,
  536. TUInt32Bit1000ModTest,
  537. TUInt32Bit60000Test,
  538. TUInt32Bit60000ModTest,
  539. TUInt32Bit146097Test,
  540. TUInt32Bit146097ModTest,
  541. TUInt32Bit3600000Test,
  542. TUInt32Bit3600000ModTest,
  543. TUInt64Bit1Test,
  544. TUInt64Bit1ModTest,
  545. TUInt64Bit2Test,
  546. TUInt64Bit2ModTest,
  547. TUInt64Bit3Test,
  548. TUInt64Bit3ModTest,
  549. TUInt64Bit7Test,
  550. TUInt64Bit7ModTest,
  551. TUInt64Bit10Test,
  552. TUInt64Bit10ModTest,
  553. TUInt64Bit100Test,
  554. TUInt64Bit100ModTest,
  555. TUInt64Bit1000000000Test,
  556. TUInt64Bit1000000000ModTest,
  557. TSInt32Bit1Test,
  558. TSInt32Bit1ModTest,
  559. TSInt32Bit100Test,
  560. TSInt32Bit100ModTest,
  561. TSInt64Bit1Test,
  562. TSInt64Bit1ModTest,
  563. TSInt64Bit10Test,
  564. TSInt64Bit10ModTest,
  565. TSInt64Bit18Test,
  566. TSInt64Bit18ModTest,
  567. TSInt64Bit24Test,
  568. TSInt64Bit24ModTest,
  569. TSInt64Bit100Test,
  570. TSInt64Bit100ModTest,
  571. TSInt64Bit153Test,
  572. TSInt64Bit153ModTest,
  573. TSInt64Bit1461Test,
  574. TSInt64Bit1461ModTest,
  575. TSInt64Bit10000Test,
  576. TSInt64Bit10000ModTest,
  577. TSInt64Bit86400000Test,
  578. TSInt64Bit86400000ModTest,
  579. TUInt32Bit3ModCmpTest,
  580. TSInt32Bit3ModCmpTest,
  581. TUInt32Bit10ModCmpTest,
  582. TSInt32Bit10ModCmpTest,
  583. TUInt32Bit100ModCmpTest,
  584. TSInt32Bit100ModCmpTest,
  585. TUInt32Bit400ModCmpTest,
  586. TUInt32Bit1000ModCmpTest,
  587. TUInt64Bit3ModCmpTest,
  588. TSInt64Bit3ModCmpTest,
  589. TUInt64Bit10ModCmpTest,
  590. TSInt64Bit10000ModCmpTest,
  591. TUInt64Bit100ModCmpTest,
  592. TSInt64Bit86400000ModCmpTest,
  593. TUInt64Bit1000000000ModCmpTest
  594. );
  595. var
  596. CurrentObject: TTestAncestor;
  597. Failed: Boolean;
  598. X: Integer;
  599. SummedUpAverageDuration, AverageDuration : Double;
  600. begin
  601. SummedUpAverageDuration := 0.0;
  602. Failed := False;
  603. WriteLn('Division compilation and timing test (using constants from System and Sysutils)');
  604. WriteLn('-------------------------------------------------------------------------------');
  605. for X := Low(TestClasses) to High(TestClasses) do
  606. begin
  607. try
  608. CurrentObject := TestClasses[X].Create;
  609. try
  610. Write(CurrentObject.TestTitle:43, ' - ');
  611. CurrentObject.Run;
  612. if CurrentObject.WriteResults then
  613. begin
  614. AverageDuration := ((CurrentObject.RunTime * 1000000000.0) / (ITERATIONS * INTERNAL_LOOPS));
  615. WriteLn('Pass - average iteration duration: ', AverageDuration:1:3, ' ns');
  616. SummedUpAverageDuration := SummedUpAverageDuration + AverageDuration;
  617. end
  618. else
  619. { Final average isn't processed if a test failed, so there's no need
  620. to calculate and add the average duration to it }
  621. Failed := True;
  622. finally
  623. CurrentObject.Free;
  624. end;
  625. except on E: Exception do
  626. begin
  627. WriteLn('Exception "', E.ClassName, '" raised while running test object of class "', TestClasses[X].ClassName, '"');
  628. Failed := True;
  629. end;
  630. end;
  631. end;
  632. if Failed then
  633. Halt(1);
  634. WriteLn(#10'ok');
  635. WriteLn('- Sum of average durations: ', SummedUpAverageDuration:1:3, ' ns');
  636. WriteLn('- Overall average duration: ', (SummedUpAverageDuration / Length(TestClasses)):1:3, ' ns');
  637. end.