/README.md

https://github.com/zandev/zanbench
Markdown | 144 lines | 118 code | 26 blank | 0 comment | 0 complexity | 1fed6e2f076912a000f33edce49570b6 MD5 | raw file
  1. zanbench is a lightweight xUnit-like actionscript 3 framework for performances testing. It allow you to write benchmarks in a xUnit like manner :
  2. * Create a BenchmarkCase by inheriting from BenchmarkCase or implementing Benchmarkable
  3. * Write tests methods (basicaly, something you want to loop over)
  4. * Tag these tests methods with the "Benchmark" metadata tag
  5. * If needed, define callback's actions in four methods :
  6. 1. prepare() : called before any test method
  7. 2. setUp() : called before each test method
  8. 3. tearDown() : called after each test method
  9. 4. clean() : called after all test methods
  10. * add your BenchmarkCase to a suite
  11. * run the suite
  12. zanbench let you split the tests methods iterations in runs, and define delay between these runs. This allow you to have more control over the system resources usage for very loud benchmarks.
  13. zanbench is in it's very first release, more features will come over time.
  14. Usage: (from ./example/simple/*)
  15. package simple
  16. {
  17. import com.zanshine.benchmark.core.BenchmarkCase;
  18. public class SimpleBenchmarkCase extends BenchmarkCase
  19. {
  20. /**
  21. * before callbacks
  22. */
  23. override public function prepare():void
  24. {
  25. comment("The prepare() method is called before any test run", "prepare");
  26. }
  27. override public function setUp():void
  28. {
  29. comment("Before each test, the setUp() method is called", "setUp");
  30. }
  31. /**
  32. * First test method
  33. */
  34. public function beforeFirstTestSimpleMethod():void
  35. {
  36. comment("You can define a before callback for any given method " +
  37. "by simply use a \"before\" prefix with the method name camelized", "beforeFirstTestSimpleMethod");
  38. }
  39. [Benchmark(order=2, message="This is a first simple test method")]
  40. public function firstTestSimpleMethod():void
  41. {
  42. comment("This is the first test method (in order of class declaration). " +
  43. "It is called after the second test method, because we've assigned it " +
  44. "an order=2 in the Benchmark metadata tag. " +
  45. "This method is where you put the code you want to benchmark. " +
  46. "Accordingly to the arguments given to the addBenchmark method in the suite, " +
  47. "this method will be called 4 times.", "firstTestSimpleMethod");
  48. }
  49. public function afterFirstTestSimpleMethod():void
  50. {
  51. comment("You can define a before callback for any given method " +
  52. "by simply use an \"after\" prefix with the method name camelized", "afterFirstTestSimpleMethod");
  53. }
  54. /**
  55. * Second test method
  56. */
  57. public function beforeSecondTestSimpleMethod():void
  58. {
  59. comment("You can define a before callback for any given method " +
  60. "by simply use a \"before\" prefix with the method name camelized", "beforeSecondTestSimpleMethod");
  61. }
  62. [Benchmark(order=1, message="This is a first simple test method")]
  63. public function secondTestSimpleMethod():void
  64. {
  65. comment("This is the second test method (in order of class declaration). " +
  66. "It is called after the second test method, because we've assigned it " +
  67. "an order=2 in the Benchmark metadata tag. " +
  68. "This method is where you put the code you want to benchmark. " +
  69. "Accordingly to the arguments given to the addBenchmark method in the suite, " +
  70. "this method will be called 4 times.", "secondTestSimpleMethod");
  71. }
  72. public function afterSecondTestSimpleMethod():void
  73. {
  74. comment("You can define a before callback for any given method " +
  75. "by simply use an \"after\" prefix with the method name camelized", "afterSecondTestSimpleMethod");
  76. }
  77. /**
  78. * After callbacks
  79. */
  80. override public function tearDown():void
  81. {
  82. comment("After each test, the tearDown() method is called", "tearDown");
  83. }
  84. override public function clean():void
  85. {
  86. comment("The clean() method is called after all tests runs", "clean");
  87. }
  88. /**
  89. * Here is an helper method :
  90. */
  91. private function comment(string:String, method:String):void
  92. {
  93. trace("\n");
  94. trace("- ##### => " + method + "() called");
  95. trace("- " + string);
  96. trace("--------------------------------------------------------");
  97. }
  98. }
  99. }
  100. And now run the tests:
  101. package
  102. {
  103. import com.zanshine.benchmark.print.ResultPrinter;
  104. import simple.SimpleBenchmarkCase;
  105. import com.zanshine.benchmark.core.BenchmarkSuite;
  106. import flash.display.Sprite;
  107. public class SimpleExampleRunner extends Sprite
  108. {
  109. public function SimpleExampleRunner()
  110. {
  111. var suite:BenchmarkSuite = new BenchmarkSuite();
  112. suite.addBenchmark(new SimpleBenchmarkCase(), 2, 2, 500);
  113. var printer:ResultPrinter = new ResultPrinter(suite);
  114. suite.run();
  115. }
  116. }
  117. }
  118. For more examples, see the example directory