1 |
#!/usr/bin/perl -w |
2 |
|
3 |
# bench_search.pl - benchmark new and old implementation of search |
4 |
# |
5 |
# 05/06/2006 11:38:32 PM CEST Dobrica Pavlinusic <dpavlin@rot13.org> |
6 |
|
7 |
use strict; |
8 |
use blib; |
9 |
use Benchmark qw/:all :hireswallclock/; |
10 |
use Search::Estraier; |
11 |
|
12 |
my $count = 100; |
13 |
my $url = 'http://localhost:1978/node/cpan'; |
14 |
|
15 |
# create and configure node |
16 |
my $node = new Search::Estraier::Node( |
17 |
url => $url, |
18 |
user => 'admin', |
19 |
passwd => 'admin', |
20 |
croak_on_error => 1, |
21 |
); |
22 |
|
23 |
# create condition |
24 |
my $cond = new Search::Estraier::Condition; |
25 |
|
26 |
my $code_ref; |
27 |
my $q = ''; |
28 |
my $l = 0; |
29 |
|
30 |
foreach my $w (qw/full text search/) { |
31 |
$q .= " $w"; |
32 |
$l++; |
33 |
|
34 |
# set search phrase |
35 |
$cond->set_phrase( $q ); |
36 |
|
37 |
$code_ref->{'old_' . $l} = sub { |
38 |
my $nres = $node->search($cond, 0) or |
39 |
die "error: ", $node->status,"\n"; |
40 |
}; |
41 |
|
42 |
$code_ref->{'new_' . $l} = sub { |
43 |
my $nres = $node->search_new($cond, 0) or |
44 |
die "error: ", $node->status,"\n"; |
45 |
}; |
46 |
} |
47 |
|
48 |
use Data::Dumper; |
49 |
print Dumper($code_ref); |
50 |
|
51 |
timethese($count, $code_ref); |
52 |
cmpthese($count, $code_ref); |
53 |
|