Old stuff/Perl/svn/scrabble/trunk/tests/Benchmarks/recherche_dichotomique.pl
(Deskargatu)
#!/usr/bin/perl -w
use Benchmark::Timer;
use strict;
my $t = Benchmark::Timer->new(skip => 1);
my $dico_file = "../../api/dico/Complet.txt";
my @words;
open(INFO,$dico_file) or die("Impossible de trouver Complet.txt");
while(<INFO>)
{
chomp;
push(@words,$_);
}
close INFO;
sub check_word($)
{
my $word = shift;
my $debut = 0;
my $fin = $#words;
my $trouve = 0;
my $milieu = int(($debut+$fin)/2)+1;
while($words[$milieu] ne $word and $debut < $fin)
{
if ($words[$milieu] lt $word)
{
$debut = $milieu+1;
}
else
{
$fin = $milieu;
}
$milieu = int (($debut+$fin)/2);
}
return ($words[$milieu] eq $word);
}
open(INFO,"echantillon.1") or die("Impossible d ouvrir ../echantillon.1");
while(<INFO>)
{
chomp;
$t -> start('tag');
check_word($_);
$t -> stop('tag');
}
print "Benchmark Result : ".$t->report."\n";