This repository was archived by the owner on Jun 18, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathbenchmark.php
More file actions
153 lines (143 loc) · 3.54 KB
/
Copy pathbenchmark.php
File metadata and controls
153 lines (143 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
*@file
*This file benchmarks a few aspects of \\RWKY\\Redis<br />
*It can benchmark magic methods vs cmd, pipelining vs no pipelining and tcp vs unix sockets<br />
*<strong>Be careful when running this file it may overwrite your redis database</strong>
*/
require("tests/tests-include.inc");
$redis=\RWKY\Redis\setUpRedis();
$tests=array("magic","pipelining","connection");
if(!isset($argv[1])) $argv[1]="all";
if($argv[1]=="all")
{
foreach($tests as $t)
{
echo "---$t---".PHP_EOL;
$t();
echo "--- ---".PHP_EOL;
}
exit;
}
array_shift($argv);
foreach($argv as $arg)
{
if(!in_array($arg,$tests))
{
echo "Invalid test $arg".PHP_EOL;
}
else{
echo "---$arg---".PHP_EOL;
$arg();
echo "--- ---".PHP_EOL;
}
}
/**
*Benchmarks using __call vs cmd
*/
function magic()
{
global $redis;
echo "Benchmarking __call vs cmd".PHP_EOL;
$redis->flushdb();
$t=microtime(true);
for($i=0;$i<10000;$i++)
{
$redis->set("key$i",$i);
}
echo "__call to set 10,000 times = ".(microtime(true)-$t)." seconds".PHP_EOL;
sleep(1);
$redis->flushdb();
echo "cmd...".PHP_EOL;
$t=microtime(true);
for($i=0;$i<10000;$i++)
{
$redis->cmd("set",array("key$i",$i));
}
echo "cmd time to set 10,000 times = ".(microtime(true)-$t)." seconds".PHP_EOL;
$redis->flushdb();
}
/**
*Benchmarks pipelining vs no pipelining
*/
function pipelining()
{
global $redis;
echo "Benchmarking set pipeline vs non pipeline".PHP_EOL;
$redis->flushdb();
$nonPipe=microtime(true);
for($i=0;$i<10000;$i++)
{
$redis->set("key$i",$i);
}
echo "Non pipelining time to set 10,000 times = ".(microtime(true)-$nonPipe)." seconds".PHP_EOL;
sleep(1);
$redis->flushdb();
echo "Pipelining...".PHP_EOL;
$pipe=microtime(true);
$redis->pipe();
for($i=0;$i<10000;$i++)
{
$redis->set("key$i",$i);
}
$redis->drain();
echo "Pipelining time to set 10,000 times = ".(microtime(true)-$pipe)." seconds".PHP_EOL;
$redis->flushdb();
}
/**
*Benchmarks tcp vs unix sockets
*/
function connection()
{
global $redis;
$redis=new \RWKY\Redis\Redis();
$redis->config("PORT",6379);
echo "Benchmarking tcp vs unix socket using pipelining".PHP_EOL;
$redis->flushdb();
$nonPipe=microtime(true);
$redis->pipe();
for($i=0;$i<10000;$i++)
{
$redis->set("key$i",$i);
}
$redis->drain();
echo "TCP time to set 10,000 times = ".(microtime(true)-$nonPipe)." seconds".PHP_EOL;
sleep(1);
$redis=new \RWKY\Redis\Redis();
$redis->config("UNIX_SOCKET","/tmp/redis-test.sock");
$redis->flushdb();
echo "Unix socket...".PHP_EOL;
$pipe=microtime(true);
$redis->pipe();
for($i=0;$i<10000;$i++)
{
$redis->set("key$i",$i);
}
$redis->drain();
echo "UNIX Socket time to set 10,000 times = ".(microtime(true)-$pipe)." seconds".PHP_EOL;
$redis->flushdb();
$redis=new \RWKY\Redis\Redis();
$redis->config("PORT",6379);
echo "Benchmarking tcp vs unix socket without using pipelining".PHP_EOL;
$redis->flushdb();
$nonPipe=microtime(true);
for($i=0;$i<10000;$i++)
{
$redis->set("key$i",$i);
}
echo "TCP time to set 10,000 times = ".(microtime(true)-$nonPipe)." seconds".PHP_EOL;
sleep(1);
$redis=new \RWKY\Redis\Redis();
$redis->config("UNIX_SOCKET","/tmp/redis-test.sock");
$redis->flushdb();
echo "Unix socket...".PHP_EOL;
$pipe=microtime(true);
for($i=0;$i<10000;$i++)
{
$redis->set("key$i",$i);
}
echo "UNIX Socket time to set 10,000 times = ".(microtime(true)-$pipe)." seconds".PHP_EOL;
$redis->flushdb();
$redis=new \RWKY\Redis\Redis();
$redis->config("PORT",6379);
}