PHPackages                             bfg/speed-test - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. bfg/speed-test

ActiveBfg-app

bfg/speed-test
==============

Designed for approximate estimation of the time of code execution by the number of iterations

1.0.0(1y ago)1241MITPHPPHP ^8.0

Since Jul 29Pushed 1y ago2 watchersCompare

[ Source](https://github.com/bfg-s/speed-test)[ Packagist](https://packagist.org/packages/bfg/speed-test)[ RSS](/packages/bfg-speed-test/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

Extension benchmark
===================

[](#extension-benchmark)

Designed for approximate estimation of the time of code execution by the number of iterations.

Install
-------

[](#install)

```
composer require bfg/speed-test --dev
```

Create bench check
------------------

[](#create-bench-check)

Suppose that we need to check how long it will work out the `bcrypt`password encryption function. Run the following command:

```
php artisan make:bench bcrypt -t 10 -l "bcrypt(time());"
```

And launch the test:

```
php artisan benchmark bcrypt
```

Config publish
--------------

[](#config-publish)

```
php artisan vendor:publish --tag=speed-test
```

Commands
--------

[](#commands)

### make:bench

[](#makebench)

Speed test maker

```
Usage:
  make:bench [options] [--] []

Arguments:
  test                             The test name

Options:
  -d, --description[=DESCRIPTION]  The description of test
  -t, --times[=TIMES]              Number of iterations [default: "10"]
  -l, --line[=LINE]                Code line in the icted function [default: "//"]
```

Your test will be created in the `tests/Benchmark` folder, you can change this in config `speed-test.dir`.

> Meaning Description and the number of iterations are indicated in the dock of the test block.

### benchmark

[](#benchmark)

Speed test runner

```
Usage:
  benchmark []

Arguments:
  test                  The name of the test case [Optional].

Options:
  -t, --times[=TIMES]   Number of iterations for all
  -l, --ls              Show list of tests
```

> You can specify the class name as a test name, or specify the name of the class together with the "@" method.

Example
-------

[](#example)

Show list my benchmarks:

```
php artisan benchmark -l
```

Output:

```
+-------------------------+------------------------------+-----------------------+-------+
| Class                   | Test                         | Description           | Times |
+-------------------------+------------------------------+-----------------------+-------+
| Tests\Benchmark\Bcrypt  | bcrypt@speed1                | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt  | bcrypt@speed2                | Double bcrypt tester  | 5     |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed1               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed2               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed3               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed4               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed5               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed6               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed7               | Bcrypt tester         | 10    |
| Tests\Benchmark\Text    | text@file_lines_get_contents | Text Speed 1          | 1000  |
| Tests\Benchmark\Text    | text@lang_in_text            | lang_in_text          | 1000  |
| Tests\Benchmark\Text    | text@tag_replace             | tag_replace           | 1000  |
| Tests\Benchmark\Text    | text@assoc                   | Assoc                 | 1000  |
| Tests\Benchmark\Text    | text@array_dots_uncollapse   | array_dots_uncollapse | 1000  |
| Tests\Benchmark\XsTest  | xs_test@speed1               | My test               | 1000  |
+-------------------------+------------------------------+-----------------------+-------+
```

I have benchmark `Text`:

```
php artisan benchmark text
```

Output:

```
Text Speed 1
 1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%  1 sec/1 sec  26.0 MiB

lang_in_text
 1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
