Timer benchmarking
These two methods can be useful in estimating the computation time of each call to the algorithm. It is not a calculation of all operations carried out by the library, but those specifically related to modules of algorithms for calculating election results.
Activate / Deactivate Timer
Internal use of the timer can be deactivated globally, it's the default. Can improve performances by a few tenths of a percent for the most demanding uses on the subject.
You must activate it before doing something.
php
use CondorcetPHP\Condorcet\Condorcet;
Condorcet::$UseTimer = false; // Default
Condorcet::$UseTimer = true; // Activate it globally
Last timer
Reference
php
<?php
use CondorcetPHP\Condorcet\Condorcet;
Condorcet::$UseTimer = true;
$electionWithVotes->getResult('RankedPairs');
$electionWithVotes->getLastTimer(); // Return 0.00112 (string)
$electionWithVotes->getResult('RankedPairs');
$electionWithVotes->getLastTimer(); // Return 0.00003 . See the cache system working!
$electionWithVotes->getResult('KemenyYoung');
$electionWithVotes->getLastTimer(true); // Return 0.14926002 (float) . KemenyYoung can be really slow....
$electionWithVotes->getResult('Copeland');
$electionWithVotes->getLastTimer(true); // Return 0.00010030 (float) . But Copeland is really fast!
Global timer
Reference
php
$electionWithVotes->getResult('RankedPairs');
$electionWithVotes->getResult('KemenyYoung');
$electionWithVotes->getResult('Copeland');
$electionWithVotes->getGlobalTimer(true); // Return 0.02600050 (float) . Time calculation, including that of the Pairwise