azuyalabs / yasumi

The easy PHP Library for calculating holidays
https://www.yasumi.dev
Other
1.04k stars 152 forks source link

Save CPU time resources on DateTimeZone creation #213

Closed pvgnd closed 4 years ago

pvgnd commented 4 years ago

Introduces a DateTimeZoneFactory to keep references of already instatiated DateTimeZone.

Benchmark used:

<?php
require 'vendor/autoload.php';
$holidays = Yasumi\Yasumi::create('France', 2019);

Run on develop branch : blackfire run --samples=20 php benchmark.php

Profiling: [########################################] 20/20
Blackfire Run completed
Graph URL https://blackfire.io/profiles/bc72f011-ad87-4c92-8472-ea90ef178aa3/graph
No tests! Create some now https://blackfire.io/docs/cookbooks/tests
No recommendations

I/O Wait     1.49ms
CPU Time     13.1ms
Memory        614KB
Wall Time    14.6ms
Network         n/a     n/a     n/a
SQL             n/a     n/a

Run on PR branch : blackfire run --samples=20 php benchmark.php

Profiling: [########################################] 20/20
Blackfire Run completed
Graph URL https://blackfire.io/profiles/7fc3116c-358c-4213-8435-c7676e84ea54/graph
No tests! Create some now https://blackfire.io/docs/cookbooks/tests
No recommendations

Wall Time    11.1ms
I/O Wait      632µs
CPU Time     10.5ms
Memory        616KB
Network         n/a     n/a     n/a
SQL             n/a     n/a

image https://blackfire.io/profiles/compare/d1d4c4ea-b553-4738-aba1-851351a01ebe/graph

stelgenhof commented 4 years ago

Thank you @pvgnd ! Looks like a good improvement. I can't access those links however. Anyway I'll check your PR in the next coming days.

Cheers! Sacha

pvgnd commented 4 years ago

@stelgenhof I just made blackfire links public

stelgenhof commented 4 years ago

Thanks @pvgnd Was able to view the profile. Very insightful.