diff --git a/src/Illuminate/Support/Benchmark.php b/src/Illuminate/Support/Benchmark.php new file mode 100644 index 000000000000..fdec6f67f274 --- /dev/null +++ b/src/Illuminate/Support/Benchmark.php @@ -0,0 +1,47 @@ +map(function ($callback) use ($iterations) { + return collect(range(1, $iterations))->map(function () use ($callback) { + gc_collect_cycles(); + + $start = hrtime(true); + + $callback(); + + return (hrtime(true) - $start) / 1000000; + })->average(); + })->when( + $benchmarkables instanceof Closure, + fn ($c) => $c->first(), + fn ($c) => $c->all(), + ); + } + + /** + * Measure a callable or array of callables over the given number of iterations, then die and dump. + * + * @param \Closure|array $benchmarkables + * @param int $iterations + * @return void + */ + public static function dd(Closure|array $benchmarkables, int $iterations = 1): void + { + dd(static::measure($benchmarkables, $iterations)); + } +}