Skip to content

Instantly share code, notes, and snippets.

@juriansluiman
Created January 24, 2014 07:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save juriansluiman/8593421 to your computer and use it in GitHub Desktop.
Save juriansluiman/8593421 to your computer and use it in GitHub Desktop.
Benchmarks ran for comparing Beanstalkd and Gearman
<?php
include 'vendor/autoload.php';
$pheanstalk = new Pheanstalk_Pheanstalk('127.0.0.1');
$pheanstalk->useTube('default');
$n = 1000000;
$start = microtime(true);
for ($i = 0; $i <= $n; $i++) {
$job = $pheanstalk->reserve();
}
$end = microtime(true);
$time = ($end - $start);
$ops = $n / $time;
echo sprintf("%d operations in %.2f seconds\n", $n, $time);
echo sprintf("Meaning %d ops per second\n", $ops);
<?php
include 'vendor/autoload.php';
$pheanstalk = new Pheanstalk_Pheanstalk('127.0.0.1');
$pheanstalk->useTube('default');
$n = 1000000;
$start = microtime(true);
for ($i = 0; $i <= $n; $i++) {
$pheanstalk->put('Foo Bar Baz');
}
$end = microtime(true);
$time = ($end - $start);
$ops = $n / $time;
echo sprintf("%d operations in %.2f seconds\n", $n, $time);
echo sprintf("Meaning %d ops per second\n", $ops);
<?php
include 'vendor/autoload.php';
$worker = new GearmanWorker;
$worker->addServer();
$worker->addFunction('test', function($job) {});
$n = 1000000;
$start = microtime(true);
for ($i=0; $i <= $n; $i++) {
$worker->work();
}
$end = microtime(true);
$time = ($end - $start);
$ops = $n / $time;
echo sprintf("%d operations in %.2f seconds\n", $n, $time);
echo sprintf("Meaning %d ops per second\n", $ops);
<?php
include 'vendor/autoload.php';
$client = new GearmanClient;
$client->addServer();
$n = 1000000;
$start = microtime(true);
for ($i = 0; $i <= $n; $i++) {
$client->doBackground('test', 'This is a test');
}
$end = microtime(true);
$time = ($end - $start);
$ops = $n / $time;
echo sprintf("%d operations in %.2f seconds\n", $n, $time);
echo sprintf("Meaning %d ops per second\n", $ops);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment