|
1 | 1 | # PHP benchmark |
2 | | -[](https://scrutinizer-ci.com/g/hyperized/benchmark/build-status/master) [](https://scrutinizer-ci.com/g/hyperized/benchmark/?branch=master) |
3 | | -[](https://app.fossa.io/projects/git%2Bgithub.com%2Fhyperized%2Fbenchmark?ref=badge_shield) |
4 | 2 |
|
5 | | -Simple PHP server benchmarking. |
| 3 | +[](https://github.com/hyperized/benchmark/actions/workflows/ci.yml) |
6 | 4 |
|
7 | | -This tool can help you determine if a hosting environment is suited for your projects in terms of: |
8 | | -- PHP.ini settings that affect uploads; |
9 | | -- CPU speed available to your PHP instance; |
10 | | -- Disk IOPS available to your PHP instance; |
11 | | -- MySQL query speed; |
| 5 | +Comprehensive PHP server benchmarking utility. Tests your hosting environment across 15 benchmark modules and reports results in milliseconds. |
12 | 6 |
|
13 | | -## How to install: |
14 | | - composer create-project hyperized/benchmark:dev-master |
15 | | - |
16 | | -Copy the `/config/config.yml.example` to `/config/config.yml` and adjust to your preferences. |
17 | | - |
18 | | -## How to run: |
| 7 | +Auto-detects CLI vs web and renders with the appropriate output mode: |
| 8 | +- **CLI** — ANSI colors with Unicode box-drawing tables |
| 9 | +- **Web** — styled HTML dashboard with responsive CSS grid layout |
19 | 10 |
|
20 | | -### Locally with CLI |
21 | | - php benchmark.php |
| 11 | +Each run saves a JSON report with a timestamp to `reports/`. |
22 | 12 |
|
23 | | -### Locally with development server |
| 13 | +## Benchmark Modules |
24 | 14 |
|
25 | | - php -S localhost:8000 benchmark.php |
26 | | - |
27 | | -### Remotely |
28 | | -Install on the server by running composer and visiting the `/benchmark.php` page of the directory the project is installed at. |
| 15 | +| Category | Module | What it measures | |
| 16 | +|----------|--------|-----------------| |
| 17 | +| **Environment** | PHP | Version, ini settings, memory limits, loaded extensions | |
| 18 | +| **I/O** | Disk I/O | File creation across 8 block sizes (512B–64KB) | |
| 19 | +| | File Read | Sequential reads across file sizes (1KB–4MB) | |
| 20 | +| | Network | DNS resolution and TCP connection latency | |
| 21 | +| **Compute** | CPU | Math functions, string operations, loops, conditionals | |
| 22 | +| | Memory | Allocation speed and peak memory per operation | |
| 23 | +| | Regex | `preg_match` and `preg_replace` across 10 pattern types | |
| 24 | +| | JSON | Encode/decode with small, medium, and large payloads | |
| 25 | +| | Serialization | `serialize` vs `json_encode` vs `var_export` (+ igbinary/msgpack if available) | |
| 26 | +| | Hashing | md5, sha1, sha256, sha512, xxh3, crc32, hmac-sha256, bcrypt, argon2id | |
| 27 | +| | Encryption | AES-128/256-CBC/GCM, ChaCha20-Poly1305 encrypt and decrypt | |
| 28 | +| | Compression | gzip, zlib, deflate (+ brotli/lzf if available) with compression ratios | |
| 29 | +| **Runtime** | Function Overhead | Named function, closure, first-class callable, static/instance method, arrow function | |
| 30 | +| | Type Casting | int/string/float/bool conversions | |
| 31 | +| | Object Instantiation | stdClass, DateTime, SplStack, SplPriorityQueue, ArrayObject | |
| 32 | +| **Database** | MySQL | Query performance (requires ext-mysqli) | |
| 33 | + |
| 34 | +All modules can be individually enabled/disabled and configured in `config/config.yml`. |
| 35 | + |
| 36 | +## Requirements |
| 37 | + |
| 38 | +- PHP >= 8.4 |
| 39 | +- ext-mysqli (for MySQL benchmarks, optional) |
| 40 | + |
| 41 | +## Installation |
| 42 | + |
| 43 | +```bash |
| 44 | +composer create-project hyperized/benchmark:dev-master |
| 45 | +cp config/config.yml.example config/config.yml |
| 46 | +``` |
| 47 | + |
| 48 | +Adjust `config/config.yml` to your preferences. Set module toggles, cycle counts, MySQL credentials, and optionally override the output format. |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +### CLI |
| 53 | + |
| 54 | +```bash |
| 55 | +php benchmark.php |
| 56 | +``` |
| 57 | + |
| 58 | +Example output: |
| 59 | + |
| 60 | +``` |
| 61 | +╔════════════════════════════════════════════════╗ |
| 62 | +║ PHP Benchmark Report ║ |
| 63 | +║ 2026-04-11 14:30:22 ║ |
| 64 | +╚════════════════════════════════════════════════╝ |
| 65 | +
|
| 66 | +── PHP ─────────────────────────────────────────── |
| 67 | +
|
| 68 | + PHP Version 8.5.4 |
| 69 | + Server CLI |
| 70 | + Max Memory 128.00 MB |
| 71 | + Max Upload 2.00 MB |
| 72 | + Max Exec Time 0 seconds |
| 73 | + Extensions 67 loaded |
| 74 | +
|
| 75 | +── Disk I/O ────────────────────────────────────── |
| 76 | +
|
| 77 | + Cycles: 100 |
| 78 | + ms (lower is better) |
| 79 | +
|
| 80 | + ┌──────────┬──────────┬──────────┬──────────┐ |
| 81 | + │ 512.00 B │ 1.00 KB │ 2.00 KB │ 4.00 KB │ ... |
| 82 | + ├──────────┼──────────┼──────────┼──────────┤ |
| 83 | + │ 9.55ms │ 9.78ms │ 9.46ms │ 10.97ms │ ... |
| 84 | + └──────────┴──────────┴──────────┴──────────┘ |
| 85 | +
|
| 86 | +── Hashing ─────────────────────────────────────── |
| 87 | +
|
| 88 | + Hash Functions (99999 cycles, ms, lower is better) |
| 89 | +
|
| 90 | + ┌──────────┬──────────┬──────────┬──────────┬──────────┐ |
| 91 | + │ md5 │ sha1 │ sha256 │ sha512 │ xxh3 │ ... |
| 92 | + ├──────────┼──────────┼──────────┼──────────┼──────────┤ |
| 93 | + │ 143.00ms │ 155.71ms │ 387.45ms │ 288.95ms │ 16.35ms │ ... |
| 94 | + └──────────┴──────────┴──────────┴──────────┴──────────┘ |
| 95 | +
|
| 96 | + ... |
| 97 | +
|
| 98 | +────────────────────────────────────────────────── |
| 99 | + Total Duration 18.657s |
| 100 | + Report saved reports/2026-04-11_143022.json |
| 101 | +────────────────────────────────────────────────── |
| 102 | +``` |
| 103 | + |
| 104 | +### Web |
| 105 | + |
| 106 | +```bash |
| 107 | +php -S localhost:8000 benchmark.php |
| 108 | +``` |
| 109 | + |
| 110 | +Open `http://localhost:8000` for a styled HTML dashboard with cards for each module. |
| 111 | + |
| 112 | +### Remote |
| 113 | + |
| 114 | +Install on the server via Composer and visit `/benchmark.php` in the browser. |
| 115 | + |
| 116 | +### Reports |
| 117 | + |
| 118 | +JSON reports are saved to `reports/` with timestamped filenames (e.g. `2026-04-11_143022.json`). Disable via `benchmark.output.report: false` in config. |
| 119 | + |
| 120 | +### Configuration |
| 121 | + |
| 122 | +All modules support `enabled: true/false` and configurable cycle counts: |
| 123 | + |
| 124 | +```yaml |
| 125 | +benchmark: |
| 126 | + output: |
| 127 | + format: ~ # null = auto-detect, 'cli', or 'html' |
| 128 | + report: true # save JSON report to reports/ |
| 129 | + php: |
| 130 | + enabled: true |
| 131 | + disk: |
| 132 | + enabled: true |
| 133 | + cycles: 100 |
| 134 | + memory: |
| 135 | + enabled: true |
| 136 | + count: 9999 |
| 137 | + network: |
| 138 | + enabled: true |
| 139 | + cycles: 3 |
| 140 | + hosts: |
| 141 | + - google.com |
| 142 | + - cloudflare.com |
| 143 | + - github.com |
| 144 | + hashing: |
| 145 | + enabled: true |
| 146 | + hashCount: 99999 |
| 147 | + passwordCount: 10 |
| 148 | + # ... see config/config.yml.example for all options |
| 149 | +``` |
29 | 150 |
|
30 | 151 | ### Security |
31 | | -Note that you might want to add additional security to your server to not expose the config.yml file to your webtraffic. |
32 | 152 |
|
33 | | -For Apache with `mod_rewrite` you can use something like this in your `.htaccess` file: |
| 153 | +If deploying to a web server, ensure `config.yml` is not publicly accessible. For Apache with `mod_rewrite`: |
34 | 154 |
|
35 | | - <Files "config.yml"> |
36 | | - deny from all |
37 | | - </Files> |
| 155 | +```apache |
| 156 | +<Files "config.yml"> |
| 157 | + deny from all |
| 158 | +</Files> |
| 159 | +``` |
38 | 160 |
|
39 | | -## Contribution |
40 | | -I'm open to improvements and new benchmarks via [pull requests](https://github.com/hyperized/benchmark/pulls) |
| 161 | +## Development |
41 | 162 |
|
42 | | -Issues can be reported through [Issues](https://github.com/hyperized/benchmark/issues). |
43 | | -Please include the full output of the script and your config file without the password. |
| 163 | +```bash |
| 164 | +composer analyse # Run PHPStan (level 8) |
| 165 | +composer cs-fix # Auto-fix code style (PER-CS2.0) |
| 166 | +composer cs-check # Check code style (dry run) |
| 167 | +``` |
44 | 168 |
|
45 | | -## Credit |
46 | | -Credit where credit is due: |
| 169 | +## Contribution |
47 | 170 |
|
48 | | -- https://github.com/odan/benchmark-php |
49 | | -- https://gist.github.com/RamadhanAmizudin/ca87f7be83c6237bb070 |
50 | | -- https://stackoverflow.com/a/25370978/1757763 |
51 | | -- http://php.net/manual/en/function.rmdir.php#119949 |
| 171 | +I'm open to improvements and new benchmarks via [pull requests](https://github.com/hyperized/benchmark/pulls). |
52 | 172 |
|
| 173 | +Issues can be reported through [Issues](https://github.com/hyperized/benchmark/issues). |
| 174 | +Please include the full output of the script and your config file without the password. |
53 | 175 |
|
54 | 176 | ## License |
55 | | -[](https://app.fossa.io/projects/git%2Bgithub.com%2Fhyperized%2Fbenchmark?ref=badge_large) |
| 177 | + |
| 178 | +MIT |
0 commit comments