Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add basic benchmark

  • Loading branch information...
commit 0dc2f5436bbd9d68d7e52b465f4eb640e352e03c 1 parent a6f11c8
@plu authored
View
1  MANIFEST.SKIP
@@ -41,3 +41,4 @@
^\.shipit
^xt.*
+^benchmark.*
View
11 benchmark/GDBenchmark.pm
@@ -0,0 +1,11 @@
+package GDBenchmark;
+
+use base qw(Gearman::Driver::Worker);
+use Moose;
+
+sub ping : Job : MinProcesses(1) : MaxProcesses(1) {
+ my ( $self, $job, $workload ) = @_;
+ return "pong";
+}
+
+1;
View
20 benchmark/bench.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Gearman::XS::Client;
+use Benchmark qw(:all) ;
+
+my $client = Gearman::XS::Client->new();
+$client->add_server( 'localhost', 4730 );
+
+timethese(
+ 50000,
+ {
+ 'plain Gearman::XS' => sub {
+ my ( $ret, $pong ) = $client->do( "ping" => '' );
+ },
+ 'Gearman::Driver' => sub {
+ my ( $ret, $pong ) = $client->do( "GDBenchmark::ping" => '' );
+ },
+ }
+);
View
7 benchmark/driver.pl
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use Gearman::Driver;
+Gearman::Driver->new_with_options( namespaces => [qw(GDBenchmark)] )->run;
View
19 benchmark/plain.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Gearman::XS::Worker;
+use Gearman::XS qw(:constants);
+use GDBenchmark;
+
+my $gdb = GDBenchmark->new();
+my $worker = Gearman::XS::Worker->new;
+$worker->add_server( 'localhost', 4730 );
+
+$worker->add_function( "ping", 0, sub { return $gdb->ping() }, {} );
+
+while (1) {
+ my $ret = $worker->work();
+ if ( $ret != GEARMAN_SUCCESS ) {
+ printf( STDERR "%s\n", $worker->error() );
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.