| 1 | <?php
|
| 2 | class Cache_Bench extends Codebench {
|
| 3 |
|
| 4 | public $loops = 100000;
|
| 5 |
|
| 6 | public $subjects = array();
|
| 7 |
|
| 8 | public $c1;
|
| 9 | public $c2;
|
| 10 |
|
| 11 | public function __construct()
|
| 12 | {
|
| 13 | parent::__construct();
|
| 14 | $this->c1 = Cache::instance();
|
| 15 | $this->c2 = Cache2::instance();
|
| 16 |
|
| 17 | // Prime both caches...
|
| 18 | $this->c1->set('key1','value');
|
| 19 | $this->c1->set('key2','value');
|
| 20 | $this->c1->set('key3','value');
|
| 21 | $this->c1->set('key4','value');
|
| 22 | $this->c1->set('key5','value');
|
| 23 | $this->c1->set('key6','value');
|
| 24 | $this->c1->set('key7','value');
|
| 25 | $this->c1->set('key8','value');
|
| 26 | $this->c1->set('key9','value');
|
| 27 | $this->c1->set('key10','value');
|
| 28 | $this->c1->set('key11','value');
|
| 29 | $this->c1->set('key12','value');
|
| 30 | $this->c1->set('key13','value');
|
| 31 | $this->c1->set('key14','value');
|
| 32 | $this->c1->set('key15','value');
|
| 33 | $this->c1->set('key16','value');
|
| 34 | $this->c1->set('key17','value');
|
| 35 | $this->c1->set('key18','value');
|
| 36 | $this->c1->set('key19','value');
|
| 37 | $this->c1->set('key20','value');
|
| 38 |
|
| 39 | $this->c2->set('key1','value');
|
| 40 | $this->c2->set('key2','value');
|
| 41 | $this->c2->set('key3','value');
|
| 42 | $this->c2->set('key4','value');
|
| 43 | $this->c2->set('key5','value');
|
| 44 | $this->c2->set('key6','value');
|
| 45 | $this->c2->set('key7','value');
|
| 46 | $this->c2->set('key8','value');
|
| 47 | $this->c2->set('key9','value');
|
| 48 | $this->c2->set('key10','value');
|
| 49 | $this->c2->set('key11','value');
|
| 50 | $this->c2->set('key12','value');
|
| 51 | $this->c2->set('key13','value');
|
| 52 | $this->c2->set('key14','value');
|
| 53 | $this->c2->set('key15','value');
|
| 54 | $this->c2->set('key16','value');
|
| 55 | $this->c2->set('key17','value');
|
| 56 | $this->c2->set('key18','value');
|
| 57 | $this->c2->set('key19','value');
|
| 58 | $this->c2->set('key20','value');
|
| 59 | }
|
| 60 |
|
| 61 | public function bench_old_single_set()
|
| 62 | {
|
| 63 | $this->c1->set('key','value');
|
| 64 | }
|
| 65 |
|
| 66 | public function bench_new_single_set()
|
| 67 | {
|
| 68 | $this->c2->set('key','value');
|
| 69 | }
|
| 70 |
|
| 71 | public function bench_old_multi_set_20_items()
|
| 72 | {
|
| 73 | $items = array('key1'=>'value','key2'=>'value','key3'=>'value','key4'=>'value','key5'=>'value','key6'=>'value','key7'=>'value','key8'=>'value','key9'=>'value','key10'=>'value','key11'=>'value','key12'=>'value','key13'=>'value','key14'=>'value','key15'=>'value','key16'=>'value','key17'=>'value','key18'=>'value','key19'=>'value','key20'=>'value');
|
| 74 | foreach ($items as $key => $value)
|
| 75 | {
|
| 76 | $this->c1->set($key, $value);
|
| 77 | }
|
| 78 | }
|
| 79 |
|
| 80 | public function bench_new_multi_set_20_items()
|
| 81 | {
|
| 82 | $items = array('key1'=>'value','key2'=>'value','key3'=>'value','key4'=>'value','key5'=>'value','key6'=>'value','key7'=>'value','key8'=>'value','key9'=>'value','key10'=>'value','key11'=>'value','key12'=>'value','key13'=>'value','key14'=>'value','key15'=>'value','key16'=>'value','key17'=>'value','key18'=>'value','key19'=>'value','key20'=>'value');
|
| 83 | $this->c2->set($items);
|
| 84 | }
|
| 85 |
|
| 86 | public function bench_old_multi_set_5_items()
|
| 87 | {
|
| 88 | $items = array('key1'=>'value','key2'=>'value','key3'=>'value','key4'=>'value','key5'=>'value');
|
| 89 | foreach ($items as $key => $value)
|
| 90 | {
|
| 91 | $this->c1->set($key, $value);
|
| 92 | }
|
| 93 | }
|
| 94 |
|
| 95 | public function bench_new_multi_set_5_items()
|
| 96 | {
|
| 97 | $items = array('key1'=>'value','key2'=>'value','key3'=>'value','key4'=>'value','key5'=>'value');
|
| 98 | $this->c2->set($items);
|
| 99 | }
|
| 100 |
|
| 101 | public function bench_old_single_get()
|
| 102 | {
|
| 103 | return $this->c1->get('key');
|
| 104 | }
|
| 105 |
|
| 106 | public function bench_new_single_get()
|
| 107 | {
|
| 108 | return $this->c2->get('key');
|
| 109 | }
|
| 110 |
|
| 111 | public function bench_old_multi_get_20_items()
|
| 112 | {
|
| 113 | $result = array();
|
| 114 | $keys = array('key1','key2','key3','key4','key5','key6','key7','key8','key9','key10','key11','key12','key13','key14','key15','key16','key17','key18','key19','key20');
|
| 115 |
|
| 116 | foreach ($keys as $key)
|
| 117 | {
|
| 118 | $result[] = $this->c1->get($key);
|
| 119 | }
|
| 120 |
|
| 121 | return $result;
|
| 122 | }
|
| 123 |
|
| 124 | public function bench_new_multi_get_20_items()
|
| 125 | {
|
| 126 | $keys = array('key1','key2','key3','key4','key5','key6','key7','key8','key9','key10','key11','key12','key13','key14','key15','key16','key17','key18','key19','key20');
|
| 127 | return $this->c2->get($keys);
|
| 128 | }
|
| 129 |
|
| 130 | public function bench_old_multi_get_5_items()
|
| 131 | {
|
| 132 | $result = array();
|
| 133 | $keys = array('key1','key2','key3','key4','key5');
|
| 134 |
|
| 135 | foreach ($keys as $key)
|
| 136 | {
|
| 137 | $result[] = $this->c1->get($key);
|
| 138 | }
|
| 139 |
|
| 140 | return $result;
|
| 141 | }
|
| 142 |
|
| 143 | public function bench_new_multi_get_5_items()
|
| 144 | {
|
| 145 | $keys = array('key1','key2','key3','key4','key5');
|
| 146 | return $this->c2->get($keys);
|
| 147 | }
|
| 148 | } |