Created
June 6, 2021 13:29
-
-
Save kiddtang/0ae691af874c39ca8812e0b628f56cf3 to your computer and use it in GitHub Desktop.
Laravel Simple Load Test Route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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