Skip to content

Instantly share code, notes, and snippets.

@jadell
Created August 24, 2011 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadell/1169394 to your computer and use it in GitHub Desktop.
Save jadell/1169394 to your computer and use it in GitHub Desktop.
benchmark script for neo4jphp batch
#!/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