-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathperf.php
More file actions
77 lines (60 loc) · 1.28 KB
/
Copy pathperf.php
File metadata and controls
77 lines (60 loc) · 1.28 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
<?php
require_once("SSDB.php");
$ssdb = new SimpleSSDB('127.0.0.1', 8888);
$DATA_LEN = 100 * 1024;
$str = str_pad('', $DATA_LEN);
$resp = $ssdb->set('key', $str);
$keys = array(
'seq' => array(),
);
for($i=0; $i<1000; $i++){
$key = sprintf('%010s', $i);
$keys['seq'][] = $key;
}
$REQUESTS = 1000;
$stime = 0;
$etime = 0;
start();
foreach($keys['seq'] as $key){
$resp = $ssdb->set($key, $str);
}
output('writeseq');
$ks = $keys['seq'];
shuffle($ks);
start();
foreach($ks as $key){
$resp = $ssdb->set($key, $str);
}
output('writerand');
start();
foreach($keys['seq'] as $key){
$resp = $ssdb->get($key);
if(strlen($resp) != $DATA_LEN){
echo "$key ERROR!\n";
die();
}
}
output('readseq');
$ks = $keys['seq'];
shuffle($ks);
start();
foreach($ks as $key){
$resp = $ssdb->get($key);
if(strlen($resp) != $DATA_LEN){
echo "$key ERROR!\n";
die();
}
}
output('readrand');
function start(){
global $stime, $etime, $DATA_LEN, $REQUESTS;
$stime = microtime(1);
}
function output($op){
global $stime, $etime, $DATA_LEN, $REQUESTS;
$etime = microtime(1);
$time_consumed = $etime - $stime;
$tpr = $time_consumed/$REQUESTS * 1000;
$sps = ($REQUESTS * $DATA_LEN)/$time_consumed/1024/1024;
printf("%-10s: %8s ms/op %10.1f MB/s\n", $op, number_format($tpr, 3), $sps);// . "ms/op\n";
}