Skip to content

Instantly share code, notes, and snippets.

@kiddtang
Created June 6, 2021 13:29
Show Gist options
  • Save kiddtang/0ae691af874c39ca8812e0b628f56cf3 to your computer and use it in GitHub Desktop.
Save kiddtang/0ae691af874c39ca8812e0b628f56cf3 to your computer and use it in GitHub Desktop.
Laravel Simple Load Test Route
<?php
use Illuminate\Support\Facades\Route;
use App\Models\User;
Route::get('/', function () {
return view('welcome');
});
Route::get('/benchmark', function () {
// Reset Datase on Each Run
\Artisan::call('migrate:fresh');
echo "Reset Database - Done <br/>";
// Write Test
User::factory()->count(100)->create();
echo "Create Dummy User - Done <br/>";
// Read Test
for ($x = 1; $x <= 200; $x++) {
$index = rand(1,100);
$user = User::find($index);
echo "My name is: $user->name, and the email is $user->email.<br>";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment