Created
August 24, 2011 22:04
-
-
Save jadell/1169394 to your computer and use it in GitHub Desktop.
benchmark script for neo4jphp batch
This file contains 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
#!/usr/bin/env php | |
<?php | |
use Everyman\Neo4j\Transport, | |
Everyman\Neo4j\Client, | |
Everyman\Neo4j\Batch, | |
Everyman\Neo4j\Relationship, | |
Everyman\Neo4j\Node; | |
error_reporting(-1); | |
ini_set('display_errors', 1); | |
function loaderTestAutoloader($sClass) | |
{ | |
$sLibPath = __DIR__.'/../lib/'; | |
$sClassFile = str_replace('\\',DIRECTORY_SEPARATOR,$sClass).'.php'; | |
$sClassPath = $sLibPath.$sClassFile; | |
if (file_exists($sClassPath)) { | |
require($sClassPath); | |
} | |
} | |
spl_autoload_register('loaderTestAutoloader'); | |
function batch($client, $create_nodes) { | |
$batch = new Batch($client); | |
$start = time(); | |
foreach(range(1, $create_nodes) as $id) { | |
$node = new Node($client); | |
$node->setProperty('stop_id', $id); | |
$batch->save($node); | |
} | |
$batch->commit(); | |
$end = time(); | |
return $end - $start; | |
} | |
function sequential($client, $create_nodes) { | |
$start = time(); | |
foreach(range(1, $create_nodes) as $id) { | |
$node = new Node($client); | |
$node->setProperty('stop_id', $id)->save(); | |
} | |
$end = time(); | |
return $end - $start; | |
} | |
$transport = new Transport('xubuntu'); | |
$client = new Client($transport); | |
$series = array(10,100,250,500,1000,5000,10000); | |
$runs = 5; | |
foreach ($series as $create_nodes) { | |
$batchTotal = 0; | |
$seqTotal = 0; | |
for ($i=0; $i<$runs; $i++) { | |
$batchTotal += $batchTime = batch($client, $create_nodes); | |
$seqTotal += $seqTime = sequential($client, $create_nodes); | |
echo "{$create_nodes}\t{$i}\t$batchTime\t$seqTime\n"; | |
} | |
$batchAvg = round($batchTotal/$runs,2); | |
$seqAvg = round($seqTotal/$runs,2); | |
echo "\t\t$batchAvg\t$seqAvg\n\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment