Created
May 29, 2012 18:19
-
-
Save jmikola/2829859 to your computer and use it in GitHub Desktop.
Mongo indexing benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$m = new Mongo(); | |
$c = $m->test->foo; | |
$c->drop(); | |
$a = microtime(true); | |
foreach (range(1,1000000) as $i) { | |
$c->insert(array('x' => $i)); | |
} | |
printf("Insertion took %f seconds\n", microtime(true) - $a); | |
$options = array( | |
array(), | |
array('background' => true), | |
array('safe' => true), | |
array('background' => true, 'safe' => true), | |
); | |
foreach ($options as $o) { | |
$c->deleteIndexes(); | |
$a = microtime(true); | |
$c->ensureIndex(array('x' => 1), $o); | |
printf("Indexing with %s took %f seconds\n", json_encode($o), microtime(true) - $a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Console output:
mongostat output: