Skip to content

[12.x] Adds Macroable trait to Illuminate/Support/Benchmark#57107

Merged
taylorotwell merged 1 commit into
laravel:12.xfrom
1tim22:12.x-macroable-benchmark
Sep 18, 2025
Merged

[12.x] Adds Macroable trait to Illuminate/Support/Benchmark#57107
taylorotwell merged 1 commit into
laravel:12.xfrom
1tim22:12.x-macroable-benchmark

Conversation

@1tim22

@1tim22 1tim22 commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants