|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Benchmark |
|
4
|
|
|
{ |
|
5
|
|
|
/** |
|
6
|
|
|
* @param \Datetime $start |
|
7
|
|
|
* @param \Datetime $end |
|
8
|
|
|
* @return float |
|
9
|
|
|
*/ |
|
10
|
|
|
public function launchRecurrGeneration(\Datetime $start, \Datetime $end) |
|
11
|
|
|
{ |
|
12
|
|
|
$startAt = microtime(true); |
|
13
|
|
|
|
|
14
|
|
|
$rule = (new \Recurr\Rule) |
|
15
|
|
|
->setStartDate($start) |
|
16
|
|
|
->setUntil($end) |
|
17
|
|
|
->setFreq('MONTHLY') |
|
18
|
|
|
; |
|
19
|
|
|
$transformer = new \Recurr\Transformer\ArrayTransformer(); |
|
20
|
|
|
$recurrences = $transformer->transform($rule); |
|
21
|
|
|
|
|
22
|
|
|
foreach ($recurrences as $recurrence) { |
|
23
|
|
|
$recurrence->getStart()->format('c'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
return microtime(true) - $startAt; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param \Datetime $start |
|
31
|
|
|
* @param \Datetime $end |
|
32
|
|
|
* @return float |
|
33
|
|
|
*/ |
|
34
|
|
|
public function launchNativePhpGeneration(\Datetime $start, \Datetime $end) |
|
35
|
|
|
{ |
|
36
|
|
|
$startAt = microtime(true); |
|
37
|
|
|
|
|
38
|
|
|
$interval = new \DateInterval('P1M'); |
|
39
|
|
|
$period = new \DatePeriod($start, $interval, $end); |
|
40
|
|
|
|
|
41
|
|
|
// Need to process results, without that, PHP native is too damn fast ! Seems results are generated when accessing data |
|
42
|
|
|
foreach ($period as $date) { |
|
43
|
|
|
$date->format('c'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return microtime(true) - $startAt; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param \Datetime $start |
|
51
|
|
|
* @param \Datetime $end |
|
52
|
|
|
* @return float |
|
53
|
|
|
*/ |
|
54
|
|
|
public function launchRecurrenceGeneration(\Datetime $start, \Datetime $end) |
|
55
|
|
|
{ |
|
56
|
|
|
$startAt = microtime(true); |
|
57
|
|
|
|
|
58
|
|
|
$recurrence = (new \Recurrence\Recurrence()) |
|
59
|
|
|
->setPeriodStartAt($start) |
|
60
|
|
|
->setPeriodEndAt($end) |
|
61
|
|
|
->setFrequency(new \Recurrence\Frequency(\Recurrence\Frequency::FREQUENCY_MONTHLY)) |
|
62
|
|
|
; |
|
63
|
|
|
$period = (new \Recurrence\DatetimeProvider($recurrence))->provide(); |
|
64
|
|
|
|
|
65
|
|
|
foreach ($period as $date) { |
|
66
|
|
|
$date->format('c'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return microtime(true) - $startAt; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
} |