| 1 | <?php
|
| 2 | class Cache_Bench2 extends Codebench {
|
| 3 |
|
| 4 | public $loops = 10000;
|
| 5 |
|
| 6 | public $subjects = array();
|
| 7 |
|
| 8 | public $c1;
|
| 9 | public $c2;
|
| 10 |
|
| 11 | public function __construct()
|
| 12 | {
|
| 13 | parent::__construct();
|
| 14 | $this->c1 = Cache2::instance();
|
| 15 | $this->c2 = Cache2::instance('memcached');
|
| 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 | $this->c1->set($items);
|
| 75 | }
|
| 76 |
|
| 77 | public function bench_new_multi_set_20_items()
|
| 78 | {
|
| 79 | $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');
|
| 80 | $this->c2->set($items);
|
| 81 | }
|
| 82 |
|
| 83 | public function bench_old_multi_set_5_items()
|
| 84 | {
|
| 85 | $items = array('key1'=>'value','key2'=>'value','key3'=>'value','key4'=>'value','key5'=>'value');
|
| 86 | $this->c1->set($items);
|
| 87 | }
|
| 88 |
|
| 89 | public function bench_new_multi_set_5_items()
|
| 90 | {
|
| 91 | $items = array('key1'=>'value','key2'=>'value','key3'=>'value','key4'=>'value','key5'=>'value');
|
| 92 | $this->c2->set($items);
|
| 93 | }
|
| 94 |
|
| 95 | public function bench_old_single_get()
|
| 96 | {
|
| 97 | return $this->c1->get('key');
|
| 98 | }
|
| 99 |
|
| 100 | public function bench_new_single_get()
|
| 101 | {
|
| 102 | return $this->c2->get('key');
|
| 103 | }
|
| 104 |
|
| 105 | public function bench_old_multi_get_20_items()
|
| 106 | {
|
| 107 | $keys = array('key1','key2','key3','key4','key5','key6','key7','key8','key9','key10','key11','key12','key13','key14','key15','key16','key17','key18','key19','key20');
|
| 108 | return $this->c1->get($keys);
|
| 109 |
|
| 110 | return $result;
|
| 111 | }
|
| 112 |
|
| 113 | public function bench_new_multi_get_20_items()
|
| 114 | {
|
| 115 | $keys = array('key1','key2','key3','key4','key5','key6','key7','key8','key9','key10','key11','key12','key13','key14','key15','key16','key17','key18','key19','key20');
|
| 116 | return $this->c2->get($keys);
|
| 117 | }
|
| 118 |
|
| 119 | public function bench_old_multi_get_5_items()
|
| 120 | {
|
| 121 | $keys = array('key1','key2','key3','key4','key5');
|
| 122 | return $this->c1->get($keys);
|
| 123 | }
|
| 124 |
|
| 125 | public function bench_new_multi_get_5_items()
|
| 126 | {
|
| 127 | $keys = array('key1','key2','key3','key4','key5');
|
| 128 | return $this->c2->get($keys);
|
| 129 | }
|
| 130 | } |