PHP code example of bfg / speed-test
1. Go to this page and download the library: Download bfg/speed-test library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bfg / speed-test example snippets
class UserController extends Controller
{
...
#[Get('/auth')]
public function index(Request $request)
{
bpoint('Auth start');
\Auth::loginUsingId(1, true);
bpoint('Update user');
\Auth::user()->touch();
bpoint('Before return');
return 'ok';
}
...
}
bash
php artisan benchmark bcrypt
bash
php artisan vendor:publish --tag=speed-test
bash
php artisan benchmark -l
bash
php artisan benchmark text
bash
Text Speed 1
1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 1 sec/1 sec 26.0 MiB
lang_in_text
1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 26.0 MiB
tag_replace
1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 1 sec/1 sec 26.0 MiB
Assoc
1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 26.0 MiB
array_dots_uncollapse
1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 26.0 MiB
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
| Test count | Total test seconds | Total test memory | Usage memory | Free memory | Memory limit | Current \ Total used % CPU |
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
| 5 | 1.3933 sec | 47.3203125 kb | 24.48337555 mb | 103.51662445 mb | 128 mb | 2.01904296875 \ 0 |
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
+------------------------------+-----------------------+-------+-----------------------+-------------------------------+------------+
| Test | Description | Times | In work | Used memory | Used % CPU |
+------------------------------+-----------------------+-------+-----------------------+-------------------------------+------------+
| text@file_lines_get_contents | Text Speed 1 | 1000 | 0.2247 | 0.000225 sec | 1.078125 kb | 0.00107813 kb | 0 |
| text@lang_in_text | lang_in_text | 1000 | 0.5282 | 0.000528 sec | 24.5 kb | 0.0245 kb | 0 |
| text@tag_replace | tag_replace | 1000 | 0.337 | 0.000337 sec | 21.7421875 kb | 0.02174219 kb | 0 |
| text@assoc | Assoc | 1000 | 0.153 | 0.000153 sec | 0.0 b | 0.0 b | 0 |
| text@array_dots_uncollapse | array_dots_uncollapse | 1000 | 0.1504 | 0.00015 sec | 0.0 b | 0.0 b | 0 |
+------------------------------+-----------------------+-------+-----------------------+-------------------------------+------------+
bash
php artisan benchmark text@assoc -t 1
bash
Assoc
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 26.0 MiB
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
| Test count | Total test seconds | Total test memory | Usage memory | Free memory | Memory limit | Current \ Total used % CPU |
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
| 1 | 0.0022 sec | 1.078125 kb | 24.42333984 mb | 103.57666016 mb | 128 mb | 2.41650390625 \ 0 |
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
+------------+-------------+-------+-----------------------+---------------------------+------------+
| Test | Description | Times | In work | Used memory | Used % CPU |
+------------+-------------+-------+-----------------------+---------------------------+------------+
| text@assoc | Assoc | 1 | 0.0022 | 0.002238 sec | 1.078125 kb | 1.078125 kb | 0 |
+------------+-------------+-------+-----------------------+---------------------------+------------+
bash
php artisan speed:watcher
bash
---------- -----------------------------------------
File app/Http/Controllers/HomeController.php
Time 21:10:35.304829
Message Auth start
Diff sec 0
---------- -----------------------------------------
---------- -----------------------------------------
File app/Http/Controllers/HomeController.php
Time 21:10:35.310332
Message Update user
Diff sec 0.0055
---------- -----------------------------------------
---------- -----------------------------------------
File app/Http/Controllers/HomeController.php
Time 21:10:35.327846
Message Before return
Diff sec 0.0175
---------- -----------------------------------------
https://example.dev/auth