mirror of
https://github.com/furyfire/trueskill.git
synced 2025-03-19 08:18:38 +00:00
Quality improvements
This commit is contained in:
134
benchmark/BasicBench.php
Normal file
134
benchmark/BasicBench.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
use DNW\Skills\Teams;
|
||||
|
||||
class BasicBench
|
||||
{
|
||||
/**
|
||||
* @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());
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user