2024-02-02 11:04:31 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-02 14:09:07 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-02-02 11:04:31 +00:00
|
|
|
namespace DNW\Skills\Benchmark;
|
|
|
|
|
|
|
|
use DNW\Skills\TrueSkill\TwoPlayerTrueSkillCalculator;
|
|
|
|
use DNW\Skills\TrueSkill\TwoTeamTrueSkillCalculator;
|
|
|
|
use DNW\Skills\TrueSkill\FactorGraphTrueSkillCalculator;
|
|
|
|
use DNW\Skills\GameInfo;
|
|
|
|
use DNW\Skills\Player;
|
|
|
|
use DNW\Skills\Team;
|
|
|
|
|
2024-06-18 12:50:00 +00:00
|
|
|
/**
|
|
|
|
* Basic Benchmarks.
|
|
|
|
*/
|
2024-02-02 11:04:31 +00:00
|
|
|
class BasicBench
|
|
|
|
{
|
|
|
|
/**
|
2024-02-02 14:53:38 +00:00
|
|
|
* To benchmark performance when using TwoPlayerTrueSkillCalculator
|
|
|
|
*
|
2024-02-02 11:04:31 +00:00
|
|
|
* @Revs(20)
|
|
|
|
* @Iterations(20)
|
|
|
|
*/
|
|
|
|
public function benchBasic2PlayersUsingTwoPlayerTrueSkillCalculator(): void
|
|
|
|
{
|
|
|
|
$gameInfo = new GameInfo();
|
|
|
|
|
|
|
|
$p1 = new Player("Winner");
|
|
|
|
$p2 = new Player("Average");
|
|
|
|
|
|
|
|
$team1 = new Team($p1, $gameInfo->getDefaultRating());
|
|
|
|
$team2 = new Team($p2, $gameInfo->getDefaultRating());
|
|
|
|
|
2024-02-21 13:48:37 +00:00
|
|
|
for ($i = 0; $i < 10; ++$i) {
|
2024-05-14 11:12:26 +00:00
|
|
|
$teams = [$team1, $team2];
|
2024-02-02 11:04:31 +00:00
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-02-02 14:53:38 +00:00
|
|
|
* To benchmark performance when using TwoTeamTrueSkillCalculator for just two players in two teams
|
|
|
|
*
|
2024-02-02 11:04:31 +00:00
|
|
|
* @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());
|
|
|
|
|
2024-02-21 13:48:37 +00:00
|
|
|
for ($i = 0; $i < 10; ++$i) {
|
2024-05-14 11:12:26 +00:00
|
|
|
$teams = [$team1, $team2];
|
2024-02-02 11:04:31 +00:00
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-02-02 14:53:38 +00:00
|
|
|
* To benchmark performance when using FactorGraphTrueSkillCalculator for just two players in two teams
|
|
|
|
*
|
2024-02-02 11:04:31 +00:00
|
|
|
* @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());
|
|
|
|
|
2024-02-21 13:48:37 +00:00
|
|
|
for ($i = 0; $i < 10; ++$i) {
|
2024-05-14 11:12:26 +00:00
|
|
|
$teams = [$team1, $team2];
|
2024-02-02 11:04:31 +00:00
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-02-02 14:53:38 +00:00
|
|
|
* To benchmark performance when using FactorGraphTrueSkillCalculator with 3 players in 3 teams
|
|
|
|
*
|
2024-02-02 11:04:31 +00:00
|
|
|
* @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());
|
|
|
|
|
2024-02-21 13:48:37 +00:00
|
|
|
for ($i = 0; $i < 10; ++$i) {
|
2024-05-14 11:12:26 +00:00
|
|
|
$teams = [$team1, $team2, $team3];
|
2024-02-02 11:04:31 +00:00
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|