summaryrefslogtreecommitdiff
path: root/bucky2/t/ping.pl
blob: 96f50f67fa0014dd03fc8a4021cd2f4b816abbda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl
use lib "../lib";
use Bucky;
tie my $timer, 'Time::Stopwatch';

print_timer($timer, "Initialized");
my $i = 0;
my $old_t = 0;
while (1)
	{
	$i++;
	my $bucky = new Bucky;
	my $threads = $bucky->db->select("comments","id > ".int rand 4598);
	if ($timer > $old_t)
		{
		$old_t++;
		print_timer($timer, "$i done, ".(sprintf("%.02f",$i/$timer))."/s");
		}
	}


sub print_timer
    { print sprintf "%3.2f s %s\n", shift, shift; }

################################################3

package Time::Stopwatch;
my $VERSION = '1.00';

use strict;
use constant HIRES => eval { local $SIG{__DIE__}; require Time::HiRes };

sub TIESCALAR {
    my $pkg = shift;
    my $time = (HIRES ? Time::HiRes::time() : time()) - (@_ ? shift() : 0);
    bless \$time, $pkg;
}

sub FETCH { (HIRES ? Time::HiRes::time() : time()) - ${$_[0]}; }
sub STORE { ${$_[0]} = (HIRES ? Time::HiRes::time() : time()) - $_[1]; }

1;