#! /usr/bin/perl use DBI; use Time::HiRes qw(gettimeofday tv_interval); use warnings; use strict; $| = 1; my $dbh = DBI->connect("dbi:Pg:dbname=phonebook", "username", "password", { RaiseError => 1, AutoCommit => 1 }); my $sth = $dbh->prepare("SELECT * FROM subscribers WHERE number = ?"); my ($count, $count0, $t0, $t1, $elapsed); $count0 = 0; $t0 = [ gettimeofday ]; while (1) { my $number = int(rand(900000)) + 100000; $sth->execute("$number"); while (my $aryref = $sth->fetchrow_arrayref()) { # the results of the query are not interesting } $count++; $t1 = [ gettimeofday ]; $elapsed = tv_interval($t0, $t1); if ($elapsed > 10) { printf "%d%s\n", ($count - $count0) / $elapsed, "/sec"; $count0 = $count; $t0 = $t1; } } $sth->finish(); $dbh->disconnect(); exit 0;