mirror of
https://github.com/itflow-org/itflow
synced 2026-03-01 03:14:52 +00:00
Reintroduce Webklex IMAP for ticket processing as PHP-IMAP is no longer being developed. This is optional for now and considered beta can be found in cron/ticket_email_parser.php
This commit is contained in:
69
plugins/vendor/illuminate/support/Benchmark.php
vendored
Normal file
69
plugins/vendor/illuminate/support/Benchmark.php
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support;
|
||||
|
||||
use Closure;
|
||||
|
||||
class Benchmark
|
||||
{
|
||||
/**
|
||||
* Measure a callable or array of callables over the given number of iterations.
|
||||
*
|
||||
* @param \Closure|array $benchmarkables
|
||||
* @param int $iterations
|
||||
* @return array|float
|
||||
*/
|
||||
public static function measure(Closure|array $benchmarkables, int $iterations = 1): array|float
|
||||
{
|
||||
return Collection::wrap($benchmarkables)->map(function ($callback) use ($iterations) {
|
||||
return Collection::range(1, $iterations)->map(function () use ($callback) {
|
||||
gc_collect_cycles();
|
||||
|
||||
$start = hrtime(true);
|
||||
|
||||
$callback();
|
||||
|
||||
return (hrtime(true) - $start) / 1_000_000;
|
||||
})->average();
|
||||
})->when(
|
||||
$benchmarkables instanceof Closure,
|
||||
fn ($c) => $c->first(),
|
||||
fn ($c) => $c->all(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Measure a callable once and return the result and duration in milliseconds.
|
||||
*
|
||||
* @template TReturn of mixed
|
||||
*
|
||||
* @param (callable(): TReturn) $callback
|
||||
* @return array{0: TReturn, 1: float}
|
||||
*/
|
||||
public static function value(callable $callback): array
|
||||
{
|
||||
gc_collect_cycles();
|
||||
|
||||
$start = hrtime(true);
|
||||
|
||||
$result = $callback();
|
||||
|
||||
return [$result, (hrtime(true) - $start) / 1_000_000];
|
||||
}
|
||||
|
||||
/**
|
||||
* Measure a callable or array of callables over the given number of iterations, then dump and die.
|
||||
*
|
||||
* @param \Closure|array $benchmarkables
|
||||
* @param int $iterations
|
||||
* @return never
|
||||
*/
|
||||
public static function dd(Closure|array $benchmarkables, int $iterations = 1): never
|
||||
{
|
||||
$result = (new Collection(static::measure(Arr::wrap($benchmarkables), $iterations)))
|
||||
->map(fn ($average) => number_format($average, 3).'ms')
|
||||
->when($benchmarkables instanceof Closure, fn ($c) => $c->first(), fn ($c) => $c->all());
|
||||
|
||||
dd($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user