File: time

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 (59 lines) | stat: -rw-r--r-- 1,554 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
53
54
55
56
57
58
59
#!/usr/bin/perl -w

use strict;

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

my(%LCache, %ACache, %Control);
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;

use Benchmark;

timethese(shift || -3, 
          {
           LinkedList_Write => sub {
               while(my($k,$v) = each %Test_Data) {
                   $LCache{$k} = $v;
               }
           },
           Array_Write => sub {
               while(my($k,$v) = each %Test_Data) {
                   $ACache{$k} = $v;
               }
           },
           Control_Write => sub {
               while(my($k,$v) = each %Test_Data) {
                   $Control{$k} = $v;
               }
           },
           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};
               }
           },
          });


__END__