Permalink
Browse files

Initial Commit.

  • Loading branch information...
ShaneMcC committed Dec 2, 2018
0 parents commit fbf784b54d554cf1628a31055c9b4a4d315273a5
Showing with 104 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +72 −0 bench.php
  3. +30 −0 config.php
@@ -0,0 +1,2 @@
participants
results.json
@@ -0,0 +1,72 @@
#!/usr/bin/php
<?php
require_once(__DIR__ . '/config.php');
$results = [];
foreach ($participants as $participant) {
$person = $participant->getName();
echo $person , ': ', "\n";
$dir = __DIR__ . '/participants/' . $person;
if (file_exists($dir)) {
echo 'Updating Repo.', "\n";
chdir($dir);
exec('git pull 2>&1');
} else {
echo 'Cloning Repo.', "\n";
mkdir($dir, 0755, true);
$output = [];
exec('git clone ' . $participant->getRepo() . ' ' . $dir . ' 2>&1', $output);
chdir($dir);
}
// Prepare.
$participant->prepare();
$results[$person] = [];
$results[$person]['name'] = $person;
$results[$person]['repo'] = $participant->getRepo();
$results[$person]['days'] = [];
// Run day.
for ($day = 1; $day <= 25; $day++) {
echo 'Day ', $day, ': ';
$results[$person]['days'][$day] = [];
// Run 10 times.
for ($i = 0; $i < 10; $i++) {
$result = $participant->run($day);
if ($result === NULL) { echo '!'; break; } else { echo $i; }
// Get the `real` time output.
$time = $result[count($result) - 3];
$time = trim(preg_replace('#^real#', '', $time));
$results[$person]['days'][$day][] = $time;
}
echo "\n";
if (empty($results[$person]['days'][$day])) {
unset($results[$person]['days'][$day]);
break;
} else {
sort($results[$person]['days'][$day]);
}
}
}
// Hardware Data
$hardware = [];
exec('lscpu 2>&1', $hardware);
$hardware = implode("\n", $hardware);
$data = [];
$data['hardware'] = $hardware;
$data['results'] = $results;
// Output Results.
file_put_contents(__DIR__ . '/results.json', json_encode($data));
@@ -0,0 +1,30 @@
<?php
$participants = [];
abstract class Participant {
abstract function getName();
abstract function getRepo();
abstract function prepare();
abstract function run($day);
}
$participants[] = new class extends Participant {
public function getName() { return 'Dataforce'; }
public function getRepo() { return 'https://github.com/ShaneMcC/aoc-2018'; }
public function prepare() {
// Ensures container is built.
exec('./docker.sh 2>&1');
}
public function run($day) {
$output = [];
$ret = -1;
exec('./docker.sh --time ' . $day . ' 2>&1', $output, $ret);
return $ret === 0 ? $output : null;
}
};

0 comments on commit fbf784b

Please sign in to comment.