1 |
dpavlin |
25 |
#!/usr/bin/perl -w |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
|
5 |
|
|
use DBD::Pg; |
6 |
|
|
use Benchmark qw(:all); |
7 |
|
|
|
8 |
|
|
my $connect = "DBI:Pg:dbname=test"; |
9 |
|
|
my $index = "/home/dpavlin/pgestraier/data/casket"; |
10 |
|
|
|
11 |
|
|
my $dbh = DBI->connect($connect,"","") || die $DBI::errstr; |
12 |
|
|
|
13 |
|
|
my $sth_old = $dbh->prepare(qq` |
14 |
|
|
select * from pgest('$index',?,?,?,?) |
15 |
|
|
`) || die $dbh->errstr(); |
16 |
|
|
|
17 |
|
|
my $sth_new = $dbh->prepare(qq` |
18 |
|
|
select * from pgest('$index',?,?,?,?,?) as (id text) |
19 |
|
|
`) || die $dbh->errstr(); |
20 |
|
|
|
21 |
|
|
sub search { |
22 |
|
|
my $sth = shift; |
23 |
|
|
|
24 |
|
|
$sth->execute(@_) || die $sth->errstr(); |
25 |
|
|
|
26 |
|
|
my @arr; |
27 |
|
|
while (my $row = $sth->fetchrow_hashref() ) { |
28 |
|
|
push @arr, $row; |
29 |
|
|
} |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
timethese( 1000, { |
33 |
|
|
'0_old' => sub { |
34 |
|
|
search($sth_old, "blade runner", undef, undef, undef); |
35 |
|
|
}, |
36 |
|
|
'1_new' => sub { |
37 |
|
|
search($sth_new, "blade runner", undef, undef, undef, "{'\@id'}"); |
38 |
|
|
}, |
39 |
|
|
'2_old' => sub { |
40 |
|
|
search($sth_old, "blade runner", undef, undef, undef); |
41 |
|
|
}, |
42 |
|
|
'3_new' => sub { |
43 |
|
|
search($sth_new, "blade runner", undef, undef, undef, "{'\@id'}"); |
44 |
|
|
}, |
45 |
|
|
'4_old' => sub { |
46 |
|
|
search($sth_old, "blade runner", undef, undef, undef); |
47 |
|
|
}, |
48 |
|
|
'5_new' => sub { |
49 |
|
|
search($sth_new, "blade runner", undef, undef, undef, "{'\@id'}"); |
50 |
|
|
}, |
51 |
|
|
}); |