Created
November 5, 2013 21:31
-
-
Save bjori/7326688 to your computer and use it in GitHub Desktop.
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 | |
$mc = new MongoClient("localhost"); | |
$collection = $mc->selectCollection("test", "data"); | |
$collection->drop(); | |
for ($i = 0; $i < 500; $i++) { | |
$collection->insert(array("document" => $i)); | |
} | |
$collection->findOne(); | |
$cursor = $collection->find(); | |
$counter = 0; | |
$t1 = microtime(true); | |
try { | |
while($cursor->hasNext()) { | |
/* This just increments the cursor position */ | |
$cursor->next(); | |
/* This returns the actual document */ | |
$doc = $cursor->current(); | |
++$counter; | |
} | |
} catch(Exception $e) { | |
echo "That went wrong!: ", $e->getMessage(); | |
} | |
// Kill references to the cursor if the data wasn't fully read | |
$cursor = NULL; | |
$t2 = microtime(true); | |
var_dump($t2-$t1); | |
printf("Took %.7f to iterate %d times over a cursor\n", $t2-$t1, $counter); |
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 -n -c php.ini it.php # PHP/5.3.27 ⮀ MongoDB/2.4.6 | |
float(0.0030438899993896) | |
Took 0.0030439 to iterate 500 times over a cursor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment