コード例 #1
0
ファイル: fill-map.php プロジェクト: vtk13/map-tests
<?php

require_once 'vendor/autoload.php';
$db = new \Vtk13\LibSql\Mysql\Mysql('localhost', 'root', '', 'test');
//$db->query('ALTER TABLE map DROP INDEX `xy`');
//$db->query('TRUNCATE map');
$db->query('DROP TABLE IF EXISTS map');
$db->query('CREATE TABLE `map` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `x` int(10) unsigned NOT NULL,
  `y` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `xy` (`x`,`y`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8');
$start = microtime(true);
for ($i = 0; $i < 1000000.0; $i++) {
    $db->insert('map', array('x' => rand(0, 1000000.0), 'y' => rand(0, 1000000.0)));
}
/*
for ($i = 0 ; $i < 10000 ; $i++) {
    // one row per request takes 280s per 1M rows (~3500 rows/s)
    // one row per request takes 272s per 1M rows (~3700 rows/s) with index
    // 100 row per request takes 13s per 1M rows (~77000 rows/s) without index
    // 100 row per request takes 26s per 1M rows (~38000 rows/s) with index

    // insert 100 rows per request
    $q = 'INSERT INTO map(x, y) VALUES';
    for ($j = 1 ; $j < 100 ; $j++) {
        $x = rand(0, 1e6);
        $y = rand(0, 1e6);
        $q .= "($x, $y),";
コード例 #2
0
ファイル: fill-database.php プロジェクト: vtk13/map-tests
<?php

require_once 'vendor/autoload.php';
$db = new \Vtk13\LibSql\Mysql\Mysql('localhost', 'root', '', 'test');
$start = microtime(true);
$db->query('TRUNCATE map');
for ($i = 0; $i < 1000000.0; $i++) {
    if ($i % 10000.0 == 0) {
        echo "{$i}\n";
    }
    $db->insert('map', array('x' => rand(0, 1000000.0), 'y' => rand(0, 1000000.0)));
}
var_dump(microtime(true) - $start);
コード例 #3
0
ファイル: test-updates.php プロジェクト: vtk13/map-tests
<?php

require_once 'vendor/autoload.php';
$db = new \Vtk13\LibSql\Mysql\Mysql('localhost', 'root', '', 'test');
$start = microtime(true);
$n = 0;
while (microtime(true) - $start < 10) {
    for ($i = 0; $i < 100; $i++) {
        $id = rand(1, 1000000.0);
        $dx = rand(-10, 10);
        $dy = rand(-10, 10);
        $db->query("UPDATE map SET x=x+({$dx}), y=y+({$dy}) WHERE id={$id}");
        $n++;
    }
}
var_dump($n);
コード例 #4
0
ファイル: test-query.php プロジェクト: vtk13/map-tests
<?php

require_once 'vendor/autoload.php';
$db = new \Vtk13\LibSql\Mysql\Mysql('localhost', 'root', '', 'test');
$start = microtime(true);
$n = 0;
$ns = [];
while (microtime(true) - $start < 10) {
    for ($i = 0; $i < 10; $i++) {
        $fx = rand(0, 1000000.0);
        $fy = rand(0, 1000000.0);
        $tx = $fx + 10000;
        $ty = $fy + 10000;
        $data = $db->select("SELECT * FROM map WHERE x BETWEEN {$fx} AND {$tx} AND y BETWEEN {$fy} AND {$ty}");
        $ns[] = count($data);
        $n++;
    }
}
var_dump(round(array_sum($ns) / count($ns)));
var_dump($n);