-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from cakephp/diff-optimization
Optimized diffInMonths() - 50% improvement
- Loading branch information
Showing
2 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Cake\Chronos\Test\Benchmark; | ||
|
||
use Cake\Chronos\Chronos; | ||
|
||
/** | ||
* @BeforeMethods({"init"}) | ||
* @AfterMethods({"shutdown"}) | ||
*/ | ||
class DiffBench | ||
{ | ||
public function init() | ||
{ | ||
$this->from = new Chronos('2019-01-01 00:00:00'); | ||
$this->to = new Chronos('2020-01-01 00:00:00'); | ||
} | ||
|
||
public function shutdown() | ||
{ | ||
} | ||
|
||
/** | ||
* @Revs(1000) | ||
* @Iterations(5) | ||
*/ | ||
public function benchDiffYears() | ||
{ | ||
$this->from->diffInYears($this->to); | ||
} | ||
|
||
/** | ||
* @Revs(1000) | ||
* @Iterations(5) | ||
*/ | ||
public function benchDiffMonths() | ||
{ | ||
$this->from->diffInMonths($this->to); | ||
} | ||
|
||
/** | ||
* @Revs(1000) | ||
* @Iterations(5) | ||
*/ | ||
public function benchDiffDays() | ||
{ | ||
$this->from->diffInDays($this->to); | ||
} | ||
} |