项目作者: phplegends

项目描述 :
A PHP package for tests
高级语言: PHP
项目地址: git://github.com/phplegends/tests.git
创建时间: 2016-05-13T19:51:54Z
项目社区:https://github.com/phplegends/tests

开源协议:MIT License

下载


PHPLegends\Test\Bench

travis-ci

Usage:

  1. <?php
  2. use PHPLegends\Tests\Bench;
  3. use PHPLegends\Tests\BenchObject;
  4. require 'vendor/autoload.php'; //Composer autoload
  5. //Function for test
  6. function foo($a, $b) {
  7. $a + $b;
  8. }
  9. $bench = new Bench;
  10. $bench->defaultCicles(500);//Set default cicles for all tests
  11. //Added callback function with string
  12. $test1 = $bench->addTest(function ($a, $b) {
  13. $baz = 'foo';
  14. $baz($a, $b);
  15. });
  16. //Setup cicles (loops) and arguments for callback
  17. $test1->cicles(15000)->args(1, 2);
  18. //Added test callback function with call_user_func_array
  19. $test2 = $bench->addTest(function($a, $b) {
  20. $baz = 'foo';
  21. call_user_func_array($baz, array($a, $b));
  22. });
  23. $test2->cicles(15000)->args(3, 2);
  24. //Call "direct" function foo
  25. $test3 = $bench->addTest(function() {
  26. foo(10, 10);
  27. });
  28. $bench->run();
  29. echo 'Test #1 (memory):', $test1->memory(), '<br>';
  30. echo 'Test #1 (time):', $test1->time(), '<hr>';
  31. echo 'Test #2 (memory):', $test2->memory(), '<br>';
  32. echo 'Test #2 (time):', $test2->time(), '<hr>';
  33. echo 'Test #3 (memory):', $test3->memory(), '<br>';
  34. echo 'Test #3 (time):', $test3->time(), '<br>';
  35. $bench = $test1 = $test2 = $test3 = null;