#!/usr/bin/perl -w

# bench_search.pl - benchmark new and old implementation of search
#
# 05/06/2006 11:38:32 PM CEST Dobrica Pavlinusic <dpavlin@rot13.org>

use strict;
use blib;
use Benchmark qw/:all :hireswallclock/;
use Search::Estraier;

my $count = 100;
my $url = 'http://localhost:1978/node/cpan';

# create and configure node
my $node = new Search::Estraier::Node(
	url => $url,
	user => 'admin',
	passwd => 'admin',
	croak_on_error => 1,
);

# create condition
my $cond = new Search::Estraier::Condition;

my $code_ref;
my $q = '';
my $l = 0;

foreach my $w (qw/full text search/) {
	$q .= " $w";
	$l++;

	# set search phrase
	$cond->set_phrase( $q );

	$code_ref->{'old_' . $l} = sub {
		my $nres = $node->search($cond, 0) or
			die "error: ", $node->status,"\n";
	};

	$code_ref->{'new_' . $l} = sub {
		my $nres = $node->search_new($cond, 0) or
			die "error: ", $node->status,"\n";
	};
}

use Data::Dumper;
print Dumper($code_ref);

timethese($count, $code_ref);
cmpthese($count, $code_ref);

