ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
bench.php
Go to the documentation of this file.
1 <?php
2 
4 
5 include __DIR__ . '/../../vendor/autoload.php';
6 
7 abstract class BenchMark {
8 
9  protected $startTime;
10  protected $iterations = 10000;
11  protected $totalTime;
12 
13  function setUp() {
14 
15  }
16 
17  abstract function test();
18 
19  function go() {
20 
21  $this->setUp();
22  $this->startTime = microtime(true);
23  $this->test();
24  $this->totalTime = microtime(true) - $this->startTime;
25  return $this->totalTime;
26 
27  }
28 
29 }
30 
31 class OneCallBack extends BenchMark {
32 
33  protected $emitter;
34  protected $iterations = 100000;
35 
36  function setUp() {
37 
38  $this->emitter = new EventEmitter();
39  $this->emitter->on('foo', function() {
40  // NOOP
41  });
42 
43  }
44 
45  function test() {
46 
47  for ($i = 0;$i < $this->iterations;$i++) {
48  $this->emitter->emit('foo', []);
49  }
50 
51  }
52 
53 }
54 
55 class ManyCallBacks extends BenchMark {
56 
57  protected $emitter;
58 
59  function setUp() {
60 
61  $this->emitter = new EventEmitter();
62  for ($i = 0;$i < 100;$i++) {
63  $this->emitter->on('foo', function() {
64  // NOOP
65  });
66  }
67 
68  }
69 
70  function test() {
71 
72  for ($i = 0;$i < $this->iterations;$i++) {
73  $this->emitter->emit('foo', []);
74  }
75 
76  }
77 
78 }
79 
81 
82  protected $emitter;
83 
84  function setUp() {
85 
86  $this->emitter = new EventEmitter();
87  for ($i = 0;$i < 100;$i++) {
88  $this->emitter->on('foo', function() {
89  }, 1000 - $i);
90  }
91 
92  }
93 
94  function test() {
95 
96  for ($i = 0;$i < $this->iterations;$i++) {
97  $this->emitter->emit('foo', []);
98  }
99 
100  }
101 
102 }
103 
105  'OneCallBack',
106  'ManyCallBacks',
107  'ManyPrioritizedCallBacks',
108 ];
109 
110 foreach ($tests as $test) {
111 
112  $testObj = new $test();
113  $result = $testObj->go();
114  echo $test . " " . $result . "\n";
115 
116 }
$totalTime
Definition: bench.php:11
$result
go()
Definition: bench.php:19
setUp()
Definition: bench.php:13
$tests
Definition: bench.php:104
$startTime
Definition: bench.php:9
$iterations
Definition: bench.php:10
EventEmitter object.
$i
Definition: disco.tpl.php:19
$test
Definition: Utf8Test.php:84