├── .editorconfig ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── bench.png ├── composer.json ├── phpbench.json ├── phpunit.xml.dist ├── src ├── AhcEnvBench.php ├── SymfonyEnvBench.php └── VlucasEnvBench.php └── tests └── test.env /.editorconfig: -------------------------------------------------------------------------------- 1 | ; http://editorconfig.org 2 | ; 3 | ; Sublime: https://github.com/sindresorhus/editorconfig-sublime 4 | ; Phpstorm: https://plugins.jetbrains.com/plugin/7294-editorconfig 5 | 6 | root = true 7 | 8 | [*] 9 | indent_style = space 10 | indent_size = 4 11 | end_of_line = lf 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | 16 | [{*.js,*.css,*.scss,*.html}] 17 | indent_size = 2 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # standards 2 | /.cache/ 3 | /.env 4 | /.idea/ 5 | /vendor/ 6 | composer.lock 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 7.3 5 | 6 | install: 7 | - composer install --prefer-dist 8 | 9 | script: 10 | - composer bench 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Jitendra Adhikari 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## adhocore/env-bench 2 | 3 | Benchmarking env loaders/parsers for PHP. 4 | 5 | Candidates: `adhocore/env`, `vlucas/dotenv`, `symfony/dotenv`. 6 | 7 | ## Usage 8 | 9 | ```bash 10 | git clone git@github.com/adhocore/env-bench.git 11 | 12 | cd env-bench 13 | 14 | composer install -o 15 | 16 | vendor/bin/phpbench run src --report aggregate 17 | ``` 18 | 19 | ### Preview 20 | 21 | | Property | Value | 22 | | ----------|:---------------:| 23 | | Machine | XPS9360 | 24 | | RAM | 16G | 25 | | Processor | i7 7550U | 26 | | SSD | 512G | 27 | | OS | Ubuntu18.04 WSL | 28 | | PHP | 7.2.7 | 29 | | PHP Ext | Opcache+Xdebug | 30 | 31 | [![Bench Preview](./bench.png "Bench Preview")](./bench.png) 32 | 33 | 34 | ### Travis Preview 35 | 36 | [![Travis Bench Preview](https://i.imgur.com/1ZAq5A1.gif "Travis Bench Preview")](https://travis-ci.com/adhocore/php-env-bench/builds/79019720) 37 | 38 | 39 | #### Caveat 40 | 41 | Retrieving has not been benchmarked because none of the other except `adhocore/env` provide a factory way of retrieval. And this **definitely** is not benchmark for native `getenv()`! 42 | -------------------------------------------------------------------------------- /bench.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adhocore/php-env-bench/7d49de08f965644f4248b744cfdea960a61e85cc/bench.png -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "adhocore/env-bench", 3 | "description": "Benchmark some of ENV loaders/parsers for PHP", 4 | "type": "library", 5 | "keywords": ["php","env-bench","env","php-env","env-benchmark"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Jitendra Adhikari", 10 | "email": "jiten.adhikary@gmail.com" 11 | } 12 | ], 13 | "autoload": { 14 | "psr-4": { 15 | "Ahc\\": "src/" 16 | }, 17 | "files": [] 18 | }, 19 | "autoload-dev": { 20 | "psr-4": { 21 | "Ahc\\Test\\": "tests/" 22 | } 23 | }, 24 | "require": { 25 | "php": ">=7.0.0", 26 | "adhocore/env": "^0.1", 27 | "vlucas/phpdotenv": "^4.1 || ^5.0", 28 | "symfony/dotenv": "^5.0", 29 | "phpbench/phpbench": "@stable" 30 | }, 31 | "require-dev": { 32 | }, 33 | "config": { 34 | "optimize-autoloader": true, 35 | "preferred-install": { 36 | "*": "dist" 37 | } 38 | }, 39 | "scripts": { 40 | "bench": "phpbench run src --report aggregate" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /phpbench.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap": "vendor/autoload.php" 3 | } 4 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 16 | ./tests/ 17 | 18 | 19 | 20 | 21 | ./src 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/AhcEnvBench.php: -------------------------------------------------------------------------------- 1 | load(__DIR__ . '/../tests/test.env', true, Loader::ALL); 15 | 16 | if ('1YZ' !== \getenv('z')) { 17 | throw new \Exception('LoadEnv failed'); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/SymfonyEnvBench.php: -------------------------------------------------------------------------------- 1 | overload(__DIR__ . '/../tests/test.env'); 15 | 16 | if ('1YZ' !== \getenv('z')) { 17 | throw new \Exception('LoadEnv failed'); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/VlucasEnvBench.php: -------------------------------------------------------------------------------- 1 | load(); 15 | 16 | if ('1YZ' !== \getenv('z')) { 17 | throw new \Exception('LoadEnv failed'); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/test.env: -------------------------------------------------------------------------------- 1 | # comment line 2 | a=1 3 | b="2" 4 | c=$3# 5 | d="lol" 6 | e= 7 | f="\"6\"" 8 | A_1=one_two 9 | E="" 10 | A_B="Apple Ball" 11 | MUL="line 1line 2" 12 | x=${a}Y 13 | z=${x}Z 14 | --------------------------------------------------------------------------------