Skip to content

Conversation

@1tim22
Copy link
Contributor

@1tim22 1tim22 commented Sep 18, 2025

Greetings All:

This simple PR updates Benchmark with the Macroable trait to allow arbitrary macro registration. For example, a macro log could be registered to log benchmark data:

use Closure; use Illuminate\Support\Benchmark; use Illuminate\Support\Facades\Log; Benchmark::macro('log', fn (Closure $callback) => Log::debug(Benchmark::measure($callback)) ); 

Which could then be invoked:

Benchmark::log(fn () => sleep(1)); // [2025-09-18 07:21:56] local.DEBUG: 1000.447882 

Customization of how benchmark data is reported would now be possible.

Thanks in advance!

--
Andrew

Updates `SupportBenchmarkTest` to test `Benchmark` macro registration Arbitrary macros may now decorate `Benchmark` to customize how benchmarks are reported or logged.
@taylorotwell taylorotwell merged commit 73dac82 into laravel:12.x Sep 18, 2025
65 checks passed
@1tim22 1tim22 deleted the 12.x-macroable-benchmark branch September 18, 2025 19:02
tegos pushed a commit to tegos/laravel-framework that referenced this pull request Sep 28, 2025
Updates `SupportBenchmarkTest` to test `Benchmark` macro registration Arbitrary macros may now decorate `Benchmark` to customize how benchmarks are reported or logged. Co-authored-by: Andrew Baron <abaron@sbts.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants