forked from lionsoul2014/ip2region
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ip2region.php
67 lines (56 loc) · 1.34 KB
/
ip2region.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* test shell for ip2region for php
*
* */
$br = (php_sapi_name() == "cli")? "":"<br>";
if(!extension_loaded('ip2region')) {
dl('ip2region.' . PHP_SHLIB_SUFFIX);
}
function getTime(){
return microtime(true) * 1000;
}
// test class
function classBtreeSearch( $ip)
{
$start = getTime();
//$data = $ip2region->btreeSearch($ip);
$data = Ip2region::btreeSearchString($ip);
$end = getTime();
var_dump($data);
echo " btree search string - taken: ", ($end - $start), "\n";
$start = getTime();
$data = Ip2region:: btreeSearch(ip2long($ip));
$end = getTime();
var_dump($data);
echo " btree search - taken: ", ($end - $start), "\n";
}
function classBinarySearch($ip)
{
$start = getTime();
$data = Ip2region::binarySearchString($ip);
$end = getTime();
var_dump($data);
echo " binary search string -taken: ", ($end - $start), "\n";
$start = getTime();
$data = Ip2region::binarySearch(ip2long($ip));
$end = getTime();
var_dump($data);
echo " binary search - taken: ", ($end - $start), "\n";
}
function test(){
$v1 = rand(0,255);
$v2 = rand(0,255);
$v3 = rand(0,255);
$v4 = rand(0,255);
$ip = "{$v1}.{$v2}.{$v3}.{$v4}";
classBtreeSearch( $ip );
classBinarySearch( $ip );
}
while(true)
{
test();
break;
usleep(5000);
}
?>