diff --git a/benchmark/BasicBench.php b/benchmark/BasicBench.php new file mode 100644 index 0000000..29b17fa --- /dev/null +++ b/benchmark/BasicBench.php @@ -0,0 +1,134 @@ +getDefaultRating()); + $team2 = new Team($p2, $gameInfo->getDefaultRating()); + + for ($i = 0; $i < 10; $i++) { + $teams = Teams::concat($team1, $team2); + + $calculator = new TwoPlayerTrueSkillCalculator(); + + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); + + $team1 = new Team($p1, $newRatings->getRating($p1)); + $team2 = new Team($p2, $newRatings->getRating($p2)); + + $newRatings->getRating($p1)->getConservativeRating(); + $newRatings->getRating($p2)->getConservativeRating(); + } + } + + /** + * @Revs(20) + * @Iterations(20) + */ + public function benchBasic2PlayersUsingTwoTeamTrueSkillCalculator(): void + { + $gameInfo = new GameInfo(); + + $p1 = new Player("Winner"); + $p2 = new Player("Average"); + + $team1 = new Team($p1, $gameInfo->getDefaultRating()); + $team2 = new Team($p2, $gameInfo->getDefaultRating()); + + for ($i = 0; $i < 10; $i++) { + $teams = Teams::concat($team1, $team2); + + $calculator = new TwoTeamTrueSkillCalculator(); + + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); + + $team1 = new Team($p1, $newRatings->getRating($p1)); + $team2 = new Team($p2, $newRatings->getRating($p2)); + + $newRatings->getRating($p1)->getConservativeRating(); + $newRatings->getRating($p2)->getConservativeRating(); + } + } + + /** + * @Revs(20) + * @Iterations(20) + */ + public function benchBasic2PlayersUsingFactorGraphTrueSkillCalculator(): void + { + $gameInfo = new GameInfo(); + + $p1 = new Player("Winner"); + $p2 = new Player("Average"); + + $team1 = new Team($p1, $gameInfo->getDefaultRating()); + $team2 = new Team($p2, $gameInfo->getDefaultRating()); + + for ($i = 0; $i < 10; $i++) { + $teams = Teams::concat($team1, $team2); + + $calculator = new FactorGraphTrueSkillCalculator(); + + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); + + $team1 = new Team($p1, $newRatings->getRating($p1)); + $team2 = new Team($p2, $newRatings->getRating($p2)); + + $newRatings->getRating($p1)->getConservativeRating(); + $newRatings->getRating($p2)->getConservativeRating(); + } + } + + /** + * @Revs(20) + * @Iterations(20) + */ + public function bench3Teams(): void + { + $gameInfo = new GameInfo(); + + $p1 = new Player("Winner"); + $p2 = new Player("Average"); + $p3 = new Player("Looser"); + + $team1 = new Team($p1, $gameInfo->getDefaultRating()); + $team2 = new Team($p2, $gameInfo->getDefaultRating()); + $team3 = new Team($p3, $gameInfo->getDefaultRating()); + + for ($i = 0; $i < 10; $i++) { + $teams = Teams::concat($team1, $team2, $team3); + + $calculator = new FactorGraphTrueSkillCalculator(); + + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2, 3]); + + $team1 = new Team($p1, $newRatings->getRating($p1)); + $team2 = new Team($p2, $newRatings->getRating($p2)); + $team3 = new Team($p3, $newRatings->getRating($p3)); + + $newRatings->getRating($p1)->getConservativeRating(); + $newRatings->getRating($p2)->getConservativeRating(); + $newRatings->getRating($p3)->getConservativeRating(); + } + } +} diff --git a/composer.json b/composer.json index 25a3a05..fa50db5 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "phpunit/phpunit": "^10", "phpstan/phpstan": "^1", "squizlabs/php_codesniffer": "*", - "vimeo/psalm": "^5.14" + "vimeo/psalm": "^5.14", + "phpmetrics/phpmetrics": "^3.0-dev" }, "autoload": { "psr-4": { @@ -25,6 +26,8 @@ "test": "vendor/bin/phpunit tests --display-warnings", "test-coverage": "vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --testdox-html output/test.html --log-junit output/test.xml", "document": "phpDocumentor --setting=graphs.enabled=true", + "benchmark": "phpbench run --report=default --output=build-artifact", + "metrics": "vendor/bin/phpmetrics --config=phpmetrics.json", "analyze": [ "@analyze-phpstan", "@analyze-psalm", @@ -32,6 +35,6 @@ ], "analyze-phpstan":"vendor/bin/phpstan analyze --error-format=raw", "analyze-psalm": "vendor/bin/psalm --no-cache", - "analyze-phpcs": "vendor/bin/phpcs --report=emacs --standard=PSR1,PSR2,PSR12 --exclude=Generic.Files.LineLength src tests" + "analyze-phpcs": "vendor/bin/phpcs --report=emacs --standard=PSR1,PSR2,PSR12 --exclude=Generic.Files.LineLength src tests benchmark" } } diff --git a/composer.lock b/composer.lock index 2aba8e7..952df3a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "667bb75c25a72b3d35f64ada9d9d9e0d", + "content-hash": "9d079e1055ee327f2d46ed48b8a25cd6", "packages": [], "packages-dev": [ { @@ -1082,6 +1082,82 @@ }, "time": "2024-01-11T11:49:22+00:00" }, + { + "name": "phpmetrics/phpmetrics", + "version": "v3.0.0rc5", + "source": { + "type": "git", + "url": "https://github.com/phpmetrics/PhpMetrics.git", + "reference": "7a4ee5d6a8233f449fb9125ad586d3880c8a1b2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpmetrics/PhpMetrics/zipball/7a4ee5d6a8233f449fb9125ad586d3880c8a1b2f", + "reference": "7a4ee5d6a8233f449fb9125ad586d3880c8a1b2f", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "nikic/php-parser": "^4", + "php": ">=8.1" + }, + "replace": { + "halleck45/php-metrics": "*", + "halleck45/phpmetrics": "*" + }, + "require-dev": { + "phake/phake": "^4.4.0", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-deprecation-rules": "^1.1", + "phpstan/phpstan-phpunit": "^1.3", + "phpstan/phpstan-strict-rules": "^1.5", + "phpunit/phpunit": "^10.3", + "roave/security-advisories": "dev-latest", + "sebastian/comparator": ">=5.0.0", + "squizlabs/php_codesniffer": "^3.7", + "symfony/dom-crawler": "^6.3", + "vimeo/psalm": "^5.15" + }, + "suggest": { + "ext-dom": "To allow XML parsing and report results.", + "ext-yaml": "To allow yaml parsing of configuration files." + }, + "bin": [ + "bin/phpmetrics" + ], + "type": "library", + "autoload": { + "psr-4": { + "Hal\\": "src/Hal" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jean-François Lépine", + "email": "lepinejeanfrancois@yahoo.fr", + "homepage": "http://www.lepine.pro", + "role": "Copyright Holder" + } + ], + "description": "Static analyzer tool for PHP : Coupling, Cyclomatic complexity, Maintainability Index, Halstead's metrics... and more !", + "homepage": "http://www.phpmetrics.org", + "keywords": [ + "analysis", + "qa", + "quality", + "testing" + ], + "support": { + "issues": "https://github.com/PhpMetrics/PhpMetrics/issues", + "source": "https://github.com/phpmetrics/PhpMetrics/tree/v3.0.0rc5" + }, + "time": "2024-01-17T10:59:12+00:00" + }, { "name": "phpstan/phpdoc-parser", "version": "1.25.0", @@ -3649,7 +3725,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "phpmetrics/phpmetrics": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/phpbench.json b/phpbench.json new file mode 100644 index 0000000..da058c9 --- /dev/null +++ b/phpbench.json @@ -0,0 +1,11 @@ +{ + "runner.bootstrap": "vendor/autoload.php", + "runner.path": "benchmark/", + "report.outputs": { + "build-artifact": { + "renderer": "html", + "path": "output/benchmark.html", + "title": "Benchmarking" + } + } +} diff --git a/phpmetrics.json b/phpmetrics.json new file mode 100644 index 0000000..126349b --- /dev/null +++ b/phpmetrics.json @@ -0,0 +1,20 @@ +{ + "composer": true, + "includes": [ + "src" + ], + "excludes": [ + "tests" + ], + "report": { + "html": "output/metrics/" + }, + "plugins": { + "git": { + "binary": "git" + }, + "junit": { + "file": "output/test.xml" + } + } +} \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index 54e6f5d..3722374 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,3 +3,4 @@ parameters: paths: - src - tests + - benchmark diff --git a/psalm.xml b/psalm.xml index 9edc19d..e43a882 100644 --- a/psalm.xml +++ b/psalm.xml @@ -11,6 +11,7 @@ + diff --git a/tests/PlayerTest.php b/tests/PlayerTest.php new file mode 100644 index 0000000..de7176f --- /dev/null +++ b/tests/PlayerTest.php @@ -0,0 +1,17 @@ +assertEquals('dummy', (string)$p); + $this->assertEquals(0.1, $p->getPartialPlayPercentage()); + $this->assertEquals(0.2, $p->getPartialUpdatePercentage()); + } +}