PHP Classes

File: testItemCache.php

Recommend this page to a friend!
  Classes of Colin McKinnon  >  Item Cache  >  testItemCache.php  >  Download  
File: testItemCache.php
Role: Example script
Content type: text/plain
Description: Test class using random data
Class: Item Cache
Store values in cache with underflow and overflow
Author: By
Last change:
Date: 10 years ago
Size: 1,719 bytes


Class file image Download
 * The code here is a rather effective demonstration of how inneffective
 * the itemcache object is for random access to a set of N values which
 * is significantly larger than the cache size M; at best the hit
 * ratio will be M/N
 * however this may still provide performance benefits using a
 * overflow + underflow handler since the resultant writes will
 * be batched. See also
 * As M->N, the hit ratio will -> 1.0
 * On the other hand if there is some implicit grouping in the
 * input set of key values, then there is likely to be a big
 * performance benefit.
// ratio is the number of gets / number of adds
'size'=>50, 'minkey'=>0, 'maxkey'=>200, 'iters'=>250000, 'rwratio'=>0.5),
'size'=>200, 'minkey'=>0, 'maxkey'=>2000, 'iters'=>250000, 'rwratio'=>0.3),
'size'=>300, 'minkey'=>0, 'maxkey'=>1000, 'iters'=>250000, 'rwratio'=>0.1),
'size'=>300, 'minkey'=>0, 'maxkey'=>400, 'iters'=>250000, 'rwratio'=>0.1)

foreach (
$tests as $t) {
$c=new itemCache($t['size']);
  for (
$i=0; $i<$t['iters']; $i++) {
$key=rand($t['minkey'], $t['maxkey']);
    if (
rand(0,100)<$t['rwratio']) {
$val=rand($t['minkey'], $t['maxkey']);
$c->add($key, $val);
    } else {
, $r
, array('hitratio' => $r['hits']/($r['hits']+$r['misses'])
'mem' => memory_get_usage()
'elapsed' => ($complete-$start)

For more information send a message to info at phpclasses dot org.