Last active
August 29, 2015 14:04
-
-
Save kawa-/2fbb9aebba6074a5ceca to your computer and use it in GitHub Desktop.
This is a benchmark script forked from mybench (http://jeremy.zawodny.com/mysql/mybench/).
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/perl -w | |
# This is a benchmark script forked from mybench (http://jeremy.zawodny.com/mysql/mybench/). | |
# Not only MySQL, Redis, MongoDB, HBase, all welcome! | |
# | |
# Usage: | |
# $ wget http://jeremy.zawodny.com/mysql/mybench/mybench-1.0.tar.gz | |
# $ tar zxvf mybench-1.0.tar.gz | |
# $ cd mybench-1.0 | |
# # download this file :) | |
# $ perl bench_general.pl | |
# | |
# Custom benchmarking: | |
# remove 'sleep 3;' in this code and write something under ### do something here!!! ### | |
use strict; | |
use MyBench; | |
use Getopt::Std; | |
use Time::HiRes qw(gettimeofday tv_interval); | |
my %opt; | |
Getopt::Std::getopt('n:r:', \%opt); | |
my $num_kids = $opt{n} || 2; | |
my $num_runs = $opt{r} || 3; | |
my $callback = sub | |
{ | |
my $id = shift; | |
my $cnt = 0; | |
my @times = (); | |
## wait for the parent to HUP me | |
local $SIG{HUP} = sub { }; | |
sleep 600; | |
while ($cnt < $num_runs) | |
{ | |
my $v = int(rand(100_000)); | |
## time the query | |
my $t0 = [gettimeofday]; | |
### do something here!!! ### | |
sleep 3; | |
my $t1 = tv_interval($t0, [gettimeofday]); | |
push @times, $t1; | |
$cnt++; | |
} | |
## cleanup | |
my @r = ($id, scalar(@times), min(@times), max(@times), avg(@times), tot(@times)); | |
return @r; | |
}; | |
my @results = MyBench::fork_and_work($num_kids, $callback); | |
MyBench::compute_results('test', @results); | |
exit; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment