UsbVarTdAllocTest.Mod 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. MODULE UsbVarTdAllocTest; (** AUTHOR "Timothée Martiel"; PURPOSE "Testing for UsbTdAllocator"; *)
  2. IMPORT Kernel, Commands, UsbVarTdAlloc;
  3. CONST
  4. Nb = 1024 * 32;
  5. (**
  6. * Measure average allocation and freeing speed for the size 16.
  7. * Usage:
  8. * UsbTdAllocatorTest.Benchmark {size} ~
  9. *)
  10. PROCEDURE Benchmark * (context: Commands.Context);
  11. VAR
  12. tds: ARRAY Nb OF ADDRESS;
  13. t: Kernel.MilliTimer;
  14. alloc: UsbVarTdAlloc.Allocator;
  15. i, size, time: LONGINT;
  16. BEGIN
  17. NEW(alloc, 4096, 32);
  18. context.out.String("Page Size: 4096");
  19. context.out.Ln;
  20. context.out.String("Block Size: 32");
  21. context.out.Ln;
  22. context.out.String("Repetitions: ");
  23. context.out.Int(Nb, 0);
  24. context.out.Ln;
  25. FOR size := 128 TO 32 BY -32 DO
  26. context.out.String("TD Size = ");
  27. context.out.Int(size, 0);
  28. context.out.Ln;
  29. context.out.String("Allocating TDs");
  30. Kernel.SetTimer(t, 30000);
  31. FOR i := 0 TO Nb - 1 DO
  32. tds[i] := alloc.Allocate(size);
  33. END;
  34. time := Kernel.Elapsed(t);
  35. context.out.String("... done");
  36. context.out.Ln;
  37. context.out.String("elapsed time: ");
  38. context.out.Int(time, 0);
  39. context.out.Ln;
  40. context.out.Update;
  41. context.out.String("Freeing TDs");
  42. Kernel.SetTimer(t, 30000);
  43. FOR i := 0 TO Nb - 1 DO
  44. alloc.Free(tds[i], size);
  45. END;
  46. time := Kernel.Elapsed(t);
  47. context.out.String("... done");
  48. context.out.Ln;
  49. context.out.String("elapsed time: ");
  50. context.out.Int(time, 0);
  51. context.out.Ln;
  52. context.out.Update
  53. END
  54. END Benchmark;
  55. (**
  56. * Measure average allocation and freeing speed for the size 16.
  57. * Usage:
  58. * UsbTdAllocatorTest.Benchmark {size} ~
  59. *)
  60. PROCEDURE Test * (context: Commands.Context);
  61. VAR
  62. tds: ARRAY Nb OF ADDRESS;
  63. t: Kernel.MilliTimer;
  64. alloc: UsbVarTdAlloc.Allocator;
  65. i, size, time: LONGINT;
  66. BEGIN
  67. NEW(alloc, 4096, 32);
  68. context.out.String("Page Size: 4096");
  69. context.out.Ln;
  70. context.out.String("Block Size: 32");
  71. context.out.Ln;
  72. context.out.String("Repetitions: ");
  73. context.out.Int(Nb, 0);
  74. context.out.Ln;
  75. FOR size := 128 TO 32 BY -32 DO
  76. context.out.String("TD Size = ");
  77. context.out.Int(size, 0);
  78. context.out.Ln;
  79. context.out.String("Allocating TDs");
  80. Kernel.SetTimer(t, 30000);
  81. FOR i := 0 TO Nb - 1 DO
  82. tds[i] := alloc.Allocate(size);
  83. ASSERT(tds[i] MOD 32 = 0);
  84. END;
  85. time := Kernel.Elapsed(t);
  86. context.out.String("... done");
  87. context.out.Ln;
  88. context.out.String("elapsed time: ");
  89. context.out.Int(time, 0);
  90. context.out.Ln;
  91. context.out.Update;
  92. context.out.String("Freeing TDs");
  93. Kernel.SetTimer(t, 30000);
  94. FOR i := 0 TO Nb - 1 DO
  95. alloc.Free(tds[i], size);
  96. END;
  97. time := Kernel.Elapsed(t);
  98. context.out.String("... done");
  99. context.out.Ln;
  100. context.out.String("elapsed time: ");
  101. context.out.Int(time, 0);
  102. context.out.Ln;
  103. context.out.Update
  104. END
  105. END Test;
  106. END UsbVarTdAllocTest.
  107. UsbVarTdAllocTest.Benchmark ~
  108. UsbVarTdAllocTest.Test ~
  109. SystemTools.Free UsbVarTdAllocTest UsbVarTdAlloc ~
  110. Compiler.Compile -b=AMD
  111. basel/USB/UsbVarTdAlloc.Mod
  112. basel/USB/UsbVarTdAllocTest.Mod
  113. ~