1 |
#!/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 |
|
14 |
sub search { |
15 |
my $def = pop; |
16 |
|
17 |
my $sth = $dbh->prepare("select * from pgest('$index',?,?,?,?,?) as ($def)") || die $dbh->errstr(); |
18 |
$sth->execute(@_) || die $sth->errstr(); |
19 |
|
20 |
my @arr; |
21 |
while (my $row = $sth->fetchrow_hashref() ) { |
22 |
push @arr, $row; |
23 |
} |
24 |
} |
25 |
|
26 |
timethese( 1000, { |
27 |
'0_seedcache' => sub { |
28 |
search("blade runner", undef, undef, undef, "{'\@id'}", 'id text'); |
29 |
}, |
30 |
'1_attr_1' => sub { |
31 |
search("blade runner", undef, undef, undef, "{'\@id'}", 'id text'); |
32 |
}, |
33 |
'2_attr_2' => sub { |
34 |
search("blade runner", undef, undef, undef, "{'\@id',\@title'}",'id text, title text'); |
35 |
}, |
36 |
'3_attr_3' => sub { |
37 |
search("blade runner", undef, undef, undef, "{'\@id',\@title','\@size'}",'id text, title text, size text'); |
38 |
}, |
39 |
'4_attr_4' => sub { |
40 |
search("blade runner", undef, undef, undef, "{'\@id',\@title','\@size','quote'}",'id text, title text, size text, quote text'); |
41 |
}, |
42 |
'5_attr_5' => sub { |
43 |
search("blade runner", undef, undef, undef, "{'\@id',\@title','\@size','quote','year'}",'id text, title text, size text, quote text, year text'); |
44 |
}, |
45 |
'5_attr_6' => sub { |
46 |
search("blade runner", undef, undef, undef, "{'\@id',\@title','\@size','quote','year',\@uri'}",'id text, title text, size text, quote text, year text, uri text'); |
47 |
}, |
48 |
'5_attr_6same' => sub { |
49 |
search("blade runner", undef, undef, undef, "{'\@id',\@id','\@id','\@id','\@id',\@id'}",'id1 text, id2 text, id3 text, id4 text, id5 text, id6 text'); |
50 |
}, |
51 |
}); |