<?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);
<?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),";
<?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);