forked from swoole/benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.php
37 lines (33 loc) · 740 Bytes
/
timer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
const N = 100000;
function test()
{
global $timers;
shuffle($timers);
$stime = microtime(true);
foreach($timers as $id)
{
swoole_timer_clear($id);
}
$etime = microtime(true);
echo "del ".N." timer :". ($etime - $stime)."s\n";
}
class TestClass
{
static function timer()
{
}
}
$timers = [];
$stime = microtime(true);
for($i = 0; $i < N; $i++)
{
$timers[] = swoole_timer_after(rand(1, 9999999), 'test');
//swoole_timer_after(rand(1, 9999999), function () {
// echo "hello world\n";
//});
//swoole_timer_after(rand(1, 9999999), array('TestClass', 'timer'));
}
$etime = microtime(true);
echo "add ".N." timer :". ($etime - $stime)."s\n";
swoole_event_wait();