<?php
require('../secache.php');
$cache = new secache;
$cache->workat('cachedata');
$times = 3000;
$succ = 0;
$fail = 0;
function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$begin_time = microtime_float();
for($i=0;$i<$times;$i++){
$key = md5($i); //You must *HASH* it by your self
$value = str_repeat('No. <strong>'.$i.'</strong> is <em style="color:red">great</em>! ',rand(1,10)); // must be a *STRING*
$cache->store($key,$value);
}
echo '<h2>Insert x '.$times .' | time = ' .( microtime_float() - $begin_time) .' ms</h2>';
//echo '<hr /><h2>test read</h2>';
$begin_time = microtime_float();
for($i=0;$i<$times;$i+=rand(1,10)){
$key = md5($i); //You must *HASH* it by your self
if($cache->fetch($key,$value)){
//echo '<p>'.$key.'=>'.$value.'</p>';
$succ++;
}else{
//echo '<p>Data get failed! <b>'.$key.'</b></p>';
$fail++;
}
}
echo '<h2>Read x '.($succ+$fail).' | time = ' .( microtime_float() - $begin_time) .' ms</h2>';
echo '<h3>Success Ratio = '.round($succ*100/($succ+$fail),2).'%</h3>';
?>