From cbf7d21604e020ac653a8508cb251bef6f0c365e Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Mon, 21 Mar 2016 15:15:20 -0500 Subject: [PATCH] Add benchmark support In order to verify changes to functions that might affect performance. Also runs benchmarks during builds for easy comparison. Refs #1 --- .travis.yml | 5 +- benchmarks/ArrayBench.php | 123 ++++++++++++++++++++++++++++++++++++++ composer.json | 10 +++- phpbench.json.dist | 4 ++ 4 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 benchmarks/ArrayBench.php create mode 100644 phpbench.json.dist diff --git a/.travis.yml b/.travis.yml index c9bda27..820f581 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,11 +13,12 @@ matrix: before_script: - travis_retry composer self-update - - travis_retry composer require phpunit/phpunit + - travis_retry composer require phpunit/phpunit phpbench/phpbench - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source script: - - vendor/bin/phpunit + - composer test + - composer bench after_script: - bash -c '[[ -f "build/logs/clover.xml" ]] && wget https://scrutinizer-ci.com/ocular.phar' diff --git a/benchmarks/ArrayBench.php b/benchmarks/ArrayBench.php new file mode 100644 index 0000000..763973b --- /dev/null +++ b/benchmarks/ArrayBench.php @@ -0,0 +1,123 @@ +words()); + } + + public function benchTail() + { + return \Equip\tail($this->words()); + } + + private function words() + { + // 100 random words + return [ + 'B-G', + 'Elavil', + 'Gal', + 'Heilbronn', + 'Jawing', + 'Northumbria', + 'Polycarp', + 'Suyog', + 'Thessalians', + 'Yemenis', + 'adheres', + 'anacardic', + 'anastasis', + 'arised', + 'averseness', + 'awright', + 'bandgaps', + 'bareboat', + 'beader', + 'bearishness', + 'boxlike', + 'buddha', + 'chain-bearer', + 'chartists', + 'clickjack', + 'cogence', + 'colorways', + 'conundrums', + 'correlate', + 'cultist', + 'directum', + 'disparity', + 'dribble', + 'earth-closet', + 'embank', + 'ethnographically', + 'evokers', + 'exclaimed', + 'favela', + 'foodist', + 'grenadilla', + 'gunning', + 'hearthrug', + 'humpy', + 'indels', + 'indeterminant', + 'inelastic', + 'innateness', + 'intering', + 'interlay', + 'ire', + 'izar', + 'jaden', + 'jest', + 'joshing', + 'leader', + 'leave-taking', + 'levitical', + 'liveryman', + 'loggias', + 'lubricous', + 'luxuria', + 'main-hatch', + 'mealie', + 'minigolf', + 'misgives', + 'moneyspinning', + 'nanomachine', + 'narrativized', + 'nepetalactone', + 'omosternum', + 'onry', + 'oppidans', + 'outproduced', + 'palpal', + 'parallelled', + 'paresseuse', + 'phlebotomy', + 'poignant', + 'poinsettias', + 'psychedelia', + 'redoute', + 'saxhorn', + 'schottische', + 'semifluid', + 'sheepishness', + 'someways', + 'striped', + 'thessalonica', + 'ticca', + 'timekiller', + 'typosquatters', + 'unclenching', + 'undersupplying', + 'unforeseeable', + 'unreckonable', + 'untaxed', + 'ushers', + 'vivers', + 'whf' + ]; + } +} diff --git a/composer.json b/composer.json index 0dcfca4..0cf79a8 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,10 @@ }, "require-dev": { }, + "suggest": { + "phpunit/phpunit": "Install globally to run unit tests", + "phpbench/phpbench": "Install globally to run benchmarks" + }, "autoload": { "files": [ "src/array.php" @@ -21,7 +25,11 @@ }, "autoload-dev": { "psr-4": { - "Equip\\as\\": "tests/" + "Equip\\Assist\\": "tests/" } + }, + "scripts": { + "bench": "phpbench run --report=aggregate --revs=100 --iterations=5", + "test": "phpunit" } } diff --git a/phpbench.json.dist b/phpbench.json.dist new file mode 100644 index 0000000..c85025f --- /dev/null +++ b/phpbench.json.dist @@ -0,0 +1,4 @@ +{ + "bootstrap": "vendor/autoload.php", + "path": "benchmarks" +}