Example #1
0
    if (is_null($ret)) {
        echo "range error! \n";
        return -1;
    }
    echo "range count: {$ret->count} \n";
    $item = $ret->root;
    while ($item) {
        echo "range item: {$item->value}  {$item->mask} \n";
        $item = $item->next;
    }
    return 0;
}
function test_count($m, $key)
{
    $ret = $m->count($key, "");
    if (is_null($ret)) {
        echo "range error! \n";
        return -1;
    }
    return 0;
}
$m = new MemLinkClient("127.0.0.1", 11001, 11002, 10);
$key = "haha";
test_create($m, $key);
test_stat($m, $key);
test_insert($m, $key);
test_count($m, $key);
test_range($m, $key);
test_tag($m, $key);
test_delete($m, $key);
test_range($m, $key);
Example #2
0
function alltest()
{
    $testnum = array(10000, 100000, 1000000, 10000000);
    $insertret = array();
    $insertfunc = array(test_insert, test_insert_short);
    $insert_test_count = 4;
    $insert_testnum = array(10000, 100000);
    foreach ($insertfunc as $func) {
        foreach ($insert_testnum as $t) {
            $insertret = array();
            for ($i = 0; $i < $insert_test_count; $i++) {
                if (array_search($func, $insertfunc) == 0) {
                    echo "====== insert long {$t} test: {$i} ======\n";
                } else {
                    echo "====== insert short {$t} test: {$i} ======\n";
                }
                $speed = $func($t);
                clearkey();
                array_push($insertret, $speed);
            }
            sort($insertret);
            array_shift($insertret);
            array_pop($insertret);
            $sum = array_sum($insertret);
            $retlen = count($insertret);
            $sp = $sum / $retlen;
            echo "====== sum:{$sum} count:{$retlen} speed: {$sp} ======\n";
        }
    }
    $rangeret = array();
    $rangefunc = array(test_range, test_range_short);
    $rangetest = array(100, 200, 1000);
    $range_test_count = 8;
    foreach ($rangefunc as $func) {
        foreach ($testnum as $t) {
            test_insert($t);
            for ($j = 0; $j < 2; $j++) {
                foreach ($rangetest as $k) {
                    $rangeret = array();
                    for ($i = 0; $i < $range_test_count; $i++) {
                        if ($j == 0) {
                            $startpos = 0;
                            $slen = $k;
                        } else {
                            $startpos = $t - $k;
                            $slen = $k;
                        }
                        if (array_search($func, $rangefunc) == 0) {
                            echo "====== range long {$t} from:{$startpos} len:{$slen} test:{$i} ======\n";
                        } else {
                            echo "====== range short {$t} from:{$startpos} len:{$slen} test:{$i} ======\n";
                        }
                        $speed = $func($startpos, $slen, 1000);
                        array_push($rangeret, $speed);
                    }
                    sort($rangeret);
                    array_shift($rangeret);
                    array_pop($rangeret);
                    $sum = array_sum($rangeret);
                    $retlen = count($rangeret);
                    $sp = $sum / $retlen;
                    echo "====== sum:{$sum} count:{$retlen} num:{$t} from:{$startpos} len:{$slen} speed: {$sp} ======\n";
                }
            }
            clearkey();
        }
    }
}