2017-06-24 01:51:41 +02:00
|
|
|
<?php
|
|
|
|
|
2017-09-12 17:05:40 +02:00
|
|
|
require __DIR__ . "/_bootstrap.php";
|
2017-06-24 01:51:41 +02:00
|
|
|
|
|
|
|
use Amp\Dns;
|
|
|
|
use Amp\Loop;
|
|
|
|
|
2017-09-09 19:40:48 +02:00
|
|
|
print "Downloading top 500 domains..." . PHP_EOL;
|
|
|
|
|
2019-01-25 02:27:47 +01:00
|
|
|
$domains = \file_get_contents("https://moz.com/top500/domains/csv");
|
|
|
|
$domains = \array_map(function ($line) {
|
|
|
|
return \trim(\explode(",", $line)[1], '"/');
|
|
|
|
}, \array_filter(\explode("\n", $domains)));
|
2017-06-24 01:51:41 +02:00
|
|
|
|
2017-09-10 11:01:27 +02:00
|
|
|
// Remove "URL" header
|
2019-01-25 02:27:47 +01:00
|
|
|
\array_shift($domains);
|
2017-09-10 11:01:27 +02:00
|
|
|
|
2017-06-24 01:51:41 +02:00
|
|
|
Loop::run(function () use ($domains) {
|
2017-09-12 17:05:40 +02:00
|
|
|
print "Starting sequential queries...\r\n\r\n";
|
2017-09-09 19:40:48 +02:00
|
|
|
|
|
|
|
$timings = [];
|
|
|
|
|
2017-06-24 01:51:41 +02:00
|
|
|
for ($i = 0; $i < 10; $i++) {
|
2019-01-25 02:27:47 +01:00
|
|
|
$start = \microtime(1);
|
|
|
|
$domain = $domains[\random_int(0, \count($domains) - 1)];
|
2017-09-09 19:40:48 +02:00
|
|
|
|
2017-06-24 01:51:41 +02:00
|
|
|
try {
|
2017-09-12 17:05:40 +02:00
|
|
|
pretty_print_records($domain, yield Dns\resolve($domain));
|
2019-01-04 18:20:52 +01:00
|
|
|
} catch (Dns\DnsException $e) {
|
2017-09-12 17:05:40 +02:00
|
|
|
pretty_print_error($domain, $e);
|
2017-06-24 01:51:41 +02:00
|
|
|
}
|
2017-09-09 19:40:48 +02:00
|
|
|
|
2019-01-25 02:27:47 +01:00
|
|
|
$time = \round(\microtime(1) - $start, 2);
|
2017-09-09 19:40:48 +02:00
|
|
|
$timings[] = $time;
|
|
|
|
|
2019-01-25 02:27:47 +01:00
|
|
|
\printf("%'-74s\r\n\r\n", " in " . $time . " ms");
|
2017-06-24 01:51:41 +02:00
|
|
|
}
|
2017-09-09 19:40:48 +02:00
|
|
|
|
2019-01-25 02:27:47 +01:00
|
|
|
$averageTime = \array_sum($timings) / \count($timings);
|
2017-09-12 17:05:40 +02:00
|
|
|
|
|
|
|
print "{$averageTime} ms for an average query." . PHP_EOL;
|
2017-06-24 01:51:41 +02:00
|
|
|
});
|