Page 99 - Open Soource Technologies 304.indd
P. 99
Unit 4: Functions
Notes
ranges of these addresses. A binary search will happen on these addresses and we have a
country for the IP. Take a look at the implementation.
Let’s see where the vanilla version of IP2C spends its time at. The results are based on 1000
iterations with Xdebug enabled and visualized by KCacheGrind. It processed about 210 IP
addresses during this time.
IO part is surprisingly low. The internal fseek,fread constitute to 2% of the execution time.
On the other hand the user level fseek which is just a wrapper alone uses 5%. readShort and
readInt takes 20% of the execution time.
function readShort() {
$a = unpack(‘n’, fread($this->m_file, 2));
return $a[1];}
function readInt() {
$a =unpack(‘N’, fread($this->m_file, 4));
return $a[1];}
function seek($offset){
fseek($this->m_file, $offset);}
Contd...
LOVELY PROFESSIONAL UNIVERSITY 93