-
Notifications
You must be signed in to change notification settings - Fork 2
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 #9 from robiningelbrecht/output-execution-time
Output execution time
- Loading branch information
Showing
18 changed files
with
296 additions
and
105 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
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
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,12 @@ | ||
<?php | ||
|
||
namespace RobinIngelbrecht\PHPUnitCoverageTools\Timer; | ||
|
||
use SebastianBergmann\Timer\Duration; | ||
|
||
interface ResourceUsageFormatter | ||
{ | ||
public function resourceUsage(Duration $duration): string; | ||
|
||
public function resourceUsageSinceStartOfRequest(): string; | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace RobinIngelbrecht\PHPUnitCoverageTools\Timer; | ||
|
||
use SebastianBergmann\Timer\Duration; | ||
use SebastianBergmann\Timer\ResourceUsageFormatter as PhpUnitResourceUsageFormatter; | ||
|
||
final class SystemResourceUsageFormatter implements ResourceUsageFormatter | ||
{ | ||
private function __construct( | ||
private readonly PhpUnitResourceUsageFormatter $resourceUsageFormatter | ||
) { | ||
} | ||
|
||
public static function create(): self | ||
{ | ||
return new self(new PhpUnitResourceUsageFormatter()); | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public function resourceUsage(Duration $duration): string | ||
{ | ||
return $this->resourceUsageFormatter->resourceUsage($duration); | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public function resourceUsageSinceStartOfRequest(): string | ||
{ | ||
return $this->resourceUsageFormatter->resourceUsageSinceStartOfRequest(); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace RobinIngelbrecht\PHPUnitCoverageTools\Timer; | ||
|
||
use SebastianBergmann\Timer\Duration; | ||
use SebastianBergmann\Timer\Timer as PhpUnitTimer; | ||
|
||
final class SystemTimer implements Timer | ||
{ | ||
private function __construct( | ||
private readonly PhpUnitTimer $timer, | ||
) { | ||
} | ||
|
||
public static function create(): self | ||
{ | ||
return new self(new PhpUnitTimer()); | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public function start(): void | ||
{ | ||
$this->timer->start(); | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public function stop(): Duration | ||
{ | ||
return $this->timer->stop(); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace RobinIngelbrecht\PHPUnitCoverageTools\Timer; | ||
|
||
use SebastianBergmann\Timer\Duration; | ||
|
||
interface Timer | ||
{ | ||
public function start(): void; | ||
|
||
public function stop(): Duration; | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use RobinIngelbrecht\PHPUnitCoverageTools\Timer\ResourceUsageFormatter; | ||
use SebastianBergmann\Timer\Duration; | ||
|
||
final class FixedResourceUsageFormatter implements ResourceUsageFormatter | ||
{ | ||
private function __construct( | ||
private readonly float $usageInMb | ||
) { | ||
} | ||
|
||
public static function withUsageInMb(float $usageInMb): self | ||
{ | ||
return new self($usageInMb); | ||
} | ||
|
||
public function resourceUsage(Duration $duration): string | ||
{ | ||
return sprintf( | ||
'Time: %s, Memory: %s MB', | ||
$duration->asString(), | ||
number_format($this->usageInMb, 2, '.', ''), | ||
); | ||
} | ||
|
||
public function resourceUsageSinceStartOfRequest(): string | ||
{ | ||
return sprintf( | ||
'Time: 00:00.350, Memory: %s MB', | ||
number_format($this->usageInMb, 2, '.', ''), | ||
); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use RobinIngelbrecht\PHPUnitCoverageTools\Timer\Timer; | ||
use SebastianBergmann\Timer\Duration; | ||
|
||
final class PausedTimer implements Timer | ||
{ | ||
private function __construct( | ||
private readonly Duration $duration | ||
) { | ||
} | ||
|
||
public static function withDuration(Duration $duration): self | ||
{ | ||
return new self($duration); | ||
} | ||
|
||
public function start(): void | ||
{ | ||
} | ||
|
||
public function stop(): Duration | ||
{ | ||
return $this->duration; | ||
} | ||
} |
Oops, something went wrong.