1<?php 2require('sqlcached_client.php'); 3 4function time_float() { 5 list($usec, $sec) = explode(" ", microtime()); 6 return ((float)$usec + (float)$sec); 7} 8 9 10$time = time(); 11 12$sc = new SQLCacheD_Client(); 13 14$sc->query("DELETE FROM cache"); 15 16$sc->query("INSERT INTO cache(key, value, time) VALUES ('a key', 'some value', $time)"); 17 18$rs = $sc->query("SELECT * FROM cache"); 19var_dump($rs); 20 21$count = 100000; 22echo "\nTiming $count inserts...\n"; 23 24$time1 = time_float(); 25for ($i = 0; $i < $count; $i++) { 26 $sc->query("INSERT INTO cache(key, value, time) VALUES ('key$i', 'value $i', $time)"); 27} 28$time2 = time_float(); 29$qps = $count / ($time2 - $time1); 30$qps = sprintf("%0.1f", $qps); 31echo "Queries per second: $qps\n"; 32 33echo "\nTiming $count selects...\n"; 34 35$time1 = time_float(); 36for ($i = 0; $i < $count; $i++) { 37 $c = rand(0, $count-1); 38 $rs = $sc->query("SELECT value FROM cache WHERE key='key$c'"); 39 if (count($rs) != 1) 40 throw new Exception("Uh oh"); 41} 42$time2 = time_float(); 43$qps = $count / ($time2 - $time1); 44$qps = sprintf("%0.1f", $qps); 45echo "Queries per second: $qps\n"; 46 47 48?> 49