Meu Benchmark – pequeno comparativo MySQL e MongoDB

maio 6th, 2010 | by | benchmark, mongodb, mysql, nosql

mai
06

Inserindo/lendo
array(“title” => “Calvin and Hobbes”);
No MYSQL – Inserção
inserindo 50k
Tempo (segundos): 26.963586091995
inserindo 50k
Tempo (segundos): 35.74323797226
inserindo 50k
Tempo (segundos): 27.360780954361
inserindo 50k
Tempo (segundos): 27.239809989929
LEITURA dos 200k: Tempo (segundos): 0.16633296012878
MongoDB – Inserção
inserindo 50k
Tempo (segundos): 6.9094848632812
inserindo 50k
Tempo (segundos): 9.049604177475
inserindo 50k
Tempo (segundos): 4.2792370319366
inserindo 50k
Tempo (segundos): 10.331115007401
LEITURA dos 200k: Tempo (segundos): 0.14360809326172
As vezes a uma diferença de 100% mas provavelmente pode ser pelo sistema estar escrevendo outras coisas no HD, pq não deixei só os testes rodando.
Mas já é uma boa comparação.
Leitura Mysql:
$q = “select COUNT(*) total from teste_mysql where title=’Calvin and Hobbes’”;
getTime();
mysql_query($q);
Leitura Mongo
getTime();
$filter = array( “title” => “Calvin and Hobbes” );
$cursor = $collection->find($filter);
//$cursor->sort(array(“title” => 1))->limit(4)->skip(0);
var_dump($cursor->count(true));
//var_dump($cursor->count());
getTime();
Código mysql

[php]
<?php
$linkk = mysql_connect("localhost","root","****");
mysql_select_db("testes", $linkk);
function getTime(){ static $tempo; if( $tempo == NULL ){ $tempo = microtime(true); } else{ echo ‘Tempo (segundos): ‘.(microtime(true)-$tempo).”; } }
$q = "insert into teste_mysql VALUES(‘Calvin and Hobbes’)";
getTime();
for($i=0;$i<50000;$i++){
mysql_query($q);
}
getTime();
echo "<br />";
exit;
?>
[/php]

Código mongoDB

[php]
<?php
$conexao = new Mongo();
$db = $conexao->testes2;
$collection = $db->teste_mongo2;

function getTime(){static $tempo; if( $tempo == NULL ){ $tempo = microtime(true); } else{ echo ‘Tempo (segundos): ‘.(microtime(true)-$tempo).”; } }

getTime();

for($i=0;$i<50000;$i++){
$obj = array( "title" => "Calvin and Hobbes" );
$collection->insert($obj);
}

getTime();
$filter = array( "title" => "Calvin and Hobbes" );
$cursor = $collection->find($filter);
var_dump($cursor->count(true));
getTime();

echo "<br />";

$conexao->close();
exit;
?>
[/php]

Authored by

One Response to “Meu Benchmark – pequeno comparativo MySQL e MongoDB”

Show / Hide Comments
  1. [...] This post was mentioned on Twitter by No-SQL BR, No-SQL BR. No-SQL BR said: Novo post no NOSQL BR: Meu Benchmark – pequeno comparativo MySQL e MongoDB http://www.suissacorp.com.br/nosqlbr/?p=22 [...]