update all test files

This commit is contained in:
Guobao Jiang 2014-02-28 17:27:47 +08:00
parent 1a88c7a898
commit 11ae619f9d
8 changed files with 61 additions and 29 deletions

View File

@ -1,6 +1,6 @@
<?php
require_once('mysql2redis.php');
$items_number=20000;
$items_number=2000000;
$tab_redis = new mysql2redis();
$tab_redis->setTBname('bench');
$tab_redis->setDBname('test');

View File

@ -33,16 +33,21 @@ class dbops {
}
}
public function query($sql,$tag='select')
public function query($sql)
{
if ($this->connect()) {
if ($tag != 'select')
{
$this->mysqli->query($sql);
return true;
}
$result = $this->mysqli->query($sql);
if (gettype($result) == 'boolean')
{
return $result;
} elseif (gettype($result) == 'object' &&
$result->num_rows == 0) {
echo "</br>"; echo "$sql";
echo "000no nummmmmmmmmmm0000";
echo "</br>";
return NULL;
}
while($row = $result->fetch_array()){
$this->data[] = $row;
}

View File

@ -69,6 +69,11 @@ class iredis
return $this->redis->hSet($key, $keysub, $value);
}
public function expire($key, $time)
{ ## set expire timeout with $time (second).
return $this->redis->setTimeout($key, $time);
}
public function del($key)
{
return $this->redis->delete($key);

View File

@ -15,7 +15,7 @@ function judge($status, $cmd)
}
}
echo "下面为测试redis的php接口类redis_face的各种命令.";
echo "下面为测试redis的php接口类iredis的各种命令.";
$rf = new iredis();

View File

@ -16,16 +16,24 @@ class looptest
$this->dbname = $dbname;
}
public function test_mysql($loop_times)
public function test_mysql($loop_times, $sql = NULL)
{
$tbname = $this->tbname;
$dbname = $this->dbname;
$start_time=microtime(true);
if ($sql == NULL) {
$sql = sprintf("select * from %s", $ops->getTBname());
}
for ($i = 0; $i < $loop_times; $i++) {
$ops = new dbops();
$ops->setTBname($tbname);
$ops->setDBname($dbname);
$sql = sprintf("select * from %s", $ops->getTBname());
$start=$i*128;
$conditions = sprintf("idx > %d and idx < %d;",
$start, $start + 1000);
$sql = sprintf("select * from %s where %s",
$tbname, $conditions);
$data = $ops->query($sql);
$ops->close();
}
@ -36,6 +44,8 @@ class looptest
public function test_redis($loop_times)
{
$tbname = $this->tbname;
$dbname = $this->dbname;
$start_time=microtime(true);
for ($i = 0; $i < $loop_times; $i++) {
## for ($j = 0; $j < 5; $j++){

View File

@ -35,19 +35,20 @@ class mysql2redis
}
public function bench($items_number, $bench='bench')
{
$del_sql = sprintf("delete from %s where idx>0;", $bench);
$this->mysql->query($del_sql,'del');
for ($i=1; $i < $items_number; $i++)
{ ## 测试前创建数据表格操作
## $del_sql = sprintf("delete from %s where idx>0;", $bench);
$del_sql = sprintf("delete from %s;", $bench);
$this->mysql->query($del_sql);
## $this->mysql->query("select * from bench;");
for ($i=0; $i < $items_number; $i++)
{
$value = sprintf("(%d,\"name%d\",\"shanghai\")",$i,$i);
$value = sprintf("(%d,\"name%d\",\"%s\")", $i, $i, $bench);
$insert_sql = sprintf("insert into %s values%s;",$bench,$value);
# echo $insert_sql;
$this->mysql->query($insert_sql,'del');
$this->mysql->query($insert_sql);
}
}
public function mysql2redis($keycol = 0)
public function mysql2redis($keycol = 0, $sql = NULL)
{
$dbname = $this->dbname;
$tbname = $this->tbname;
@ -56,7 +57,11 @@ class mysql2redis
$this->mysql->setDBname($dbname);
$this->mysql->setTBname($tbname);
$sql = sprintf("select * from %s", $tbname);
if ($sql == NULL)
{
$sql = sprintf("select * from %s", $tbname);
}
$this->mysql_data = $this->mysql->query($sql);
if ($this->mysql_data == NULL)
{

View File

@ -6,7 +6,7 @@
<body>
<?php
require_once('iredis_test.php');
# require_once('iredis_test.php');
require_once('redis_action.php');
?>

View File

@ -9,7 +9,9 @@ require_once('mysql2redis.php');
require_once('looptest.php');
#$tbname="account";
#$tbname="temp";
$tbname="bench_no_index";
#$tbname="bench";
$dbname="test";
$loop_times=10;
$items_number=30000;
@ -17,29 +19,34 @@ $items_number=30000;
$tab_redis = new mysql2redis();
$tab_redis->setTBname($tbname);
$tab_redis->setDBname($dbname);
$tab_redis->mysql2redis($tbname);
#$tab_redis->bench($items_number);
# $tab_redis->bench($items_number, $tbname); ## 创建数据表格
$sql = sprintf("select * from %s where idx > 29000 and idx < 30000", $tbname);
$tab_redis->mysql2redis($tbname, $sql);
######### 下面为测试调用
$lptest = new looptest();
$lptest->configure($tbname, $dbname);
echo "<br/>";
echo "redis性能测试页面";
$dbtime=$lptest->test_mysql($loop_times);
$dbtime=$lptest->test_mysql($loop_times, $sql);
echo "<br/>"; echo "<br/>";
echo "[数据库".$dbname."".$tbname."]执行 $loop_times 次循环时间为:";
echo $dbtime;
echo "[数据库".$dbname."".$tbname."]执行 $loop_times 次循环(单次时间 ms)为:";
echo ($dbtime/$loop_times)*1000;
$rstime=$lptest->test_mysql($loop_times);
$rstime=$lptest->test_redis($loop_times);
echo "<br/>"; echo "<br/>";
echo "[redis对应表".$tbname." ]执行 $loop_times 次循环时间为:";
echo $rstime;
echo "[redis对应表".$tbname." ]执行 $loop_times 次循环(单次时间 ms)为:";
echo ($rstime/$loop_times)*1000;
echo "<br/>"; echo "<br/>";
echo "item=$items_number [数据库]/[redis]比值为:";
echo $dbtime/$rstime;
######### 下面为测试输出
#$tab_redis->print_mysql_table();
# var_dump($data);