GeoIP2-php/bin/benchmark.php
Gregory Oschwald 2f9746c32b Relax City and Country database checks
The strict database checks broke the per-continent City databases,
and adding all of those to an array is a bit much (and slow).

Closes #23.
2014-09-12 07:06:12 -07:00

27 lines
599 B
PHP
Executable File

#!/usr/bin/env php
<?php
require_once '../vendor/autoload.php';
use GeoIp2\Database\Reader;
use GeoIp2\Exception\AddressNotFoundException;
$reader = new Reader('GeoLite2-City.mmdb');
$count = 40000;
$startTime = microtime(true);
for ($i = 0; $i < $count; $i++) {
$ip = long2ip(rand(0, pow(2, 32) -1));
try {
$t = $reader->city($ip);
} catch (AddressNotFoundException $e) {
}
if ($i % 1000 == 0) {
print($i . ' ' . $ip . "\n");
}
}
$endTime = microtime(true);
$duration = $endTime - $startTime;
print('Requests per second: ' . $count / $duration . "\n");