File: read

package info (click to toggle)
libtie-cache-lru-perl 20150301-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 528 kB
  • sloc: perl: 563; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl -w

use strict;
use Benchmark;
use Tie::Cache::LRU::LinkedList;
use Tie::Cache::LRU::Array;
use FindBin qw($Bin);


sub fill_cache {
    my($cache, $data) = @_;

    while(my($k,$v) = each %{$data}) {
        $cache->{$k} = $v;
    }
}

my(%LCache, %Control, %ACache);
tie %LCache, 'Tie::Cache::LRU::LinkedList', 500;
tie %ACache, 'Tie::Cache::LRU::Array', 500;

# Pull it into memory so I/O isn't an issue.
open(TEST_DATA, "$Bin/big_test_data") || die "Can't find test data: $!";
my %Test_Data = map { chomp; $_ } <TEST_DATA>;

printf "Test data size is %d keys.\n\n", scalar keys %Test_Data;

fill_cache(\%LCache, \%Test_Data);
fill_cache(\%ACache, \%Test_Data);
fill_cache(\%Control, \%Test_Data);

timethese(shift || -3,
          {
           LinkedList_Read => sub {
               my $foo;
               while(my($k,$v) = each %Test_Data) {
                   $foo = $LCache{$k};
               }
           },
           Array_Read => sub {
               my $foo;
               while(my($k,$v) = each %Test_Data) {
                   $foo = $ACache{$k};
               }
           },
           Control_Read => sub {
               my $foo;
               while(my($k,$v) = each %Test_Data) {
                   $foo = $Control{$k};
               }
           },
          });