Get started to handle millions of votes

Benchmark shows that on PHP + SQLite, 200 000 votes can be registered and computed in less than 60 seconds on a little server, with ~60mb RAM use. However, the speed of the driver does not change the performance. From a certain point: slowdowns are intrinsically linked to the internal processing side Condorcet engine (integrity check, abstraction...). Major optimizations for speed could be done, but this would require a trade-off between speed and code complexity. We believe that the current performance is acceptable.

Condorcet provides a driver for PDO, that allows you to use the most current relational databases. You can extend it to get more optimization. Or works on your own driver to use - for example - noSQL database.

Note: Please consider this functionality as experimental. The most complex and specific usages are not well-tested or supported. And most of time, it's not necessary with a smart usage of Vote Weight instead.

Handle millions of votes with default PDO driver

use CondorcetPHP\Condorcet\{Election};
use CondorcetPHP\Condorcet\DataManager\DataHandlerDrivers\PdoDriver\PdoHandlerDriver;
use CondorcetPHP\Condorcet\Tools\Randomizers\VotesRandomGenerator;

// II - Create Election

$election = new Election;
$election->parseCandidates('A;B;C;D;E;F');

// II - Setup external drivers

/* We will use PDO SQLITE, but can be MySQL or else */

$sqlitePath = __DIR__.'/bdd.sqlite';

if (file_exists($sqlitePath)) {
    unlink($sqlitePath);
}

$driver = new PdoHandlerDriver(new \PDO('sqlite:'.$sqlitePath), true);
$election->setExternalDataHandler($driver);

// III - Add hundred of thousands votes

$howMany = 100_000;
$votesRandomizer = new VotesRandomGenerator($election->getCandidatesList());

for ($i = 0; $i < $howMany; $i++) {
    $election->addVote($votesRandomizer->getNewVote());
}


// IV - Get somes results
$election->getCondorcetWinner();
$election->getResult('Schulze');

Create your own driver

Read at the dedicated chapted

Use GetVotesListGenerator

Election->getVotesListGenerator()

If you use an external Driver handler for managing billions of votes. And want to use Election->getVotesList() method. You'll probably blow up the available memory.
Instead, use Election->getVotesListGenerator method, returning a PHP generator.