naoya / perl-algorithm-mtf
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
58adee3
commit 58adee360d9814d2071a259ddc9814b6872eefe9
tree 7e23a75640ca1bde601389ccaece8c0bacbae073
parent a55dcf05aa0e98257a9ccc76db5c902e62ca76cc
tree 7e23a75640ca1bde601389ccaece8c0bacbae073
parent a55dcf05aa0e98257a9ccc76db5c902e62ca76cc
perl-algorithm-mtf / bench.pl
| a55dcf05 » | naoya | 2008-10-19 | 1 | #!/usr/bin/env perl | |
| 2 | use strict; | ||||
| 3 | use warnings; | ||||
| 4 | use FindBin::libs; | ||||
| 5 | |||||
| 6 | use Perl6::Say; | ||||
| 7 | use Algorithm::DivSufSort; | ||||
| 8 | use Benchmark; | ||||
| 9 | use Path::Class qw/file/; | ||||
| 10 | |||||
| 11 | use Algorithm::MTF; | ||||
| 12 | use Algorithm::MTF::List; | ||||
| 13 | use Algorithm::MTF::Array; | ||||
| 14 | |||||
| 15 | sub bs_encode ($) { | ||||
| 16 | my $text = shift; | ||||
| 17 | my $sa = divsufsort( $text ); | ||||
| 18 | |||||
| 19 | my @text = unpack('C*', $text); | ||||
| 20 | return join '', map { chr $text[$_ -1] } @$sa; | ||||
| 21 | } | ||||
| 22 | |||||
| 58adee36 » | naoya | 2008-10-19 | 23 | my $bwt = bs_encode file('/etc/httpd/conf/mime.types')->slurp; | |
| a55dcf05 » | naoya | 2008-10-19 | 24 | ||
| 25 | my $list = Algorithm::MTF::List->new; | ||||
| 26 | for (my $i = 0xff; $i >= 0; $i--) { | ||||
| 27 | $list->insert(chr $i); | ||||
| 58adee36 » | naoya | 2008-10-19 | 28 | # $list->insert( Algorithm::MTF::List::Node->new(chr $i) ); | |
| a55dcf05 » | naoya | 2008-10-19 | 29 | } | |
| 30 | my $list_mtf = Algorithm::MTF::Encoder->new($list); | ||||
| 31 | |||||
| 32 | my $array = Algorithm::MTF::Array->new; | ||||
| 58adee36 » | naoya | 2008-10-19 | 33 | for (my $i = 0; $i < 0x100; $i++) { | |
| a55dcf05 » | naoya | 2008-10-19 | 34 | $array->[$i] = chr $i; | |
| 35 | } | ||||
| 36 | my $array_mtf = Algorithm::MTF::Encoder->new($array); | ||||
| 37 | |||||
| 58adee36 » | naoya | 2008-10-19 | 38 | timethese(10, { | |
| a55dcf05 » | naoya | 2008-10-19 | 39 | list => sub { | |
| 40 | $list_mtf->encode($bwt); | ||||
| 41 | }, | ||||
| 58adee36 » | naoya | 2008-10-19 | 42 | # array => sub { | |
| 43 | # $array_mtf->encode($bwt); | ||||
| 44 | # }, | ||||
| a55dcf05 » | naoya | 2008-10-19 | 45 | }); | |
