gradints / laravel-benchmark-route
Adds elapsed time to controller response
Package info
github.com/gradints/laravel-benchmark-route
Type:laravel-plugin
pkg:composer/gradints/laravel-benchmark-route
v0.0.3
2026-04-21 06:54 UTC
Requires
- php: ^8.2
- illuminate/http: >=10.0 <14.0
- illuminate/support: >=10.0 <14.0
Requires (Dev)
- laravel/pint: ^1.29
- phpunit/phpunit: ^13.1
README
This package provides a middleware that adds the elapsed time of a controller action to the response headers. It is designed to be used in Laravel applications and can be easily integrated into your existing routes.
Installation
You can install the package via Composer:
composer require --dev gradints/laravel-benchmark-route
After installing it, you need to register the middleware in your bootstrap/app.php file:
use Gradin\LaravelBenchmarkRoute\Middleware\BenchmarkMiddleware; use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Exceptions; use Illuminate\Foundation\Configuration\Middleware; use Sentry\Laravel\Integration; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', api: __DIR__.'/../routes/api.php', commands: __DIR__.'/../routes/console.php', channels: __DIR__.'/../routes/channels.php', health: '/up', apiPrefix: '', ) ->withMiddleware(function (Middleware $middleware): void { // register BenchmarkMiddleware for web and api routes $middleware->web(BenchmarkMiddleware::class); $middleware->api(BenchmarkMiddleware::class); });
Usage
use Gradin\LaravelBenchmarkRoute\Attributes\Benchmark; use Illuminate\Http\Resources\Json\JsonResource; class ProductController extends Controller { #[Benchmark] public function index() { $products = Product::paginate(20); return JsonResource::collection($products); } }
And the response will be like this:
{
"data": [
// products
],
"meta": {
// pagination meta data
},
"benchmark": {
"time": "1,230.93"
}
}
You can also give boolean as an argument to enable or disable the benchmark
#[Benchmark(true)] #[Benchmark(false)]