Open Journal Systems  3.3.0
benchmark.php
1 #!/usr/bin/php -q
2 <?php
3 
4 set_time_limit('300');
5 
6 include("geoip.inc");
7 include("geoipcity.inc");
8 define("GEOIP_COUNTRY_DATABASE",0);
9 define("GEOIP_REGION_DATABASE",1);
10 define("GEOIP_CITY_DATABASE",2);
11 
12 class mainappc{
13  var $dbfilename = array("/usr/local/share/GeoIP/GeoIP.dat","/usr/local/share/GeoIP/GeoIPRegion.dat","/usr/local/share/GeoIP/GeoIPCity.dat");
14  function randomipaddress(){
15  $result = "";
16  for ($a = 0;$a < 4;$a++){
17  if ($a > 0){$result = $result . ".";}
18  $a2 = rand(1, 254);
19  $result = $result . $a2;
20  }
21  return $result;
22  }
23  function ftime(){
24  $a = gettimeofday();
25  return $a[sec] + ($a[usec]*0.000001);
26  }
27  function testgeoipdatabase($type,$flags,$msg,$numlookups){
28  $gi = geoip_open($this->dbfilename[$type],$flags);
29  if ($gi == null){
30  print "error: " . $this->dbfilename[$type] . " does not exist\n" ;
31  return;
32  }
33  $t1 = $this->ftime();
34  $i4 = 0;
35  for ($i2 = 0;$i2 < $numlookups;$i2++){
36  switch ($type) {
37  case GEOIP_COUNTRY_DATABASE:
38  geoip_country_code_by_addr($gi,$this->randomipaddress());
39  break;
40  case GEOIP_REGION_DATABASE:
41  geoip_region_by_addr($gi,$this->randomipaddress());
42  break;
43  case GEOIP_CITY_DATABASE:
44  GeoIP_record_by_addr($gi,$this->randomipaddress());
45  break;
46  }
47  }
48  $t2 = $this->ftime();
49  $t3 = $t2-$t1;
50  print $msg . "\n";
51  print $numlookups . " lookups made in " . $t3 . " seconds \n";
52  geoip_close($gi);
53  }
54 }
55 
56 
57 $mainapp = new mainappc();
58 
59 
60 $mainapp->testgeoipdatabase(GEOIP_COUNTRY_DATABASE,GEOIP_STANDARD,"Geoip Country ",10000);
61 $mainapp->testgeoipdatabase(GEOIP_COUNTRY_DATABASE,GEOIP_MEMORY_CACHE,"Geoip Country with memory cache",10000);
62 $mainapp->testgeoipdatabase(GEOIP_REGION_DATABASE,GEOIP_STANDARD,"Geoip Region ",10000);
63 $mainapp->testgeoipdatabase(GEOIP_REGION_DATABASE,GEOIP_MEMORY_CACHE,"Geoip Region with memory cache",10000);
64 $mainapp->testgeoipdatabase(GEOIP_CITY_DATABASE,GEOIP_STANDARD,"Geoip City ",10000);
65 $mainapp->testgeoipdatabase(GEOIP_CITY_DATABASE,GEOIP_MEMORY_CACHE,"Geoip City with memory cache",10000);
66 
67 ?>
mainappc\testgeoipdatabase
testgeoipdatabase($type, $flags, $msg, $numlookups)
Definition: benchmark.php:27
mainappc
Definition: benchmark.php:12
mainappc\ftime
ftime()
Definition: benchmark.php:23
mainappc\$dbfilename
$dbfilename
Definition: benchmark.php:13
mainappc\randomipaddress
randomipaddress()
Definition: benchmark.php:14