| 12
 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
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 
 | #!/usr/bin/perl
use strict;
use warnings;
use KiokuDB;
use KiokuDB::Backend::Hash;
$| = 1;
my $f = (require KiokuDB::Test::Fixture::Small)->new;
my $mxsd_hash = KiokuDB->new(
    backend => KiokuDB::Backend::Hash->new,
);
my $q_employee = Search::GIN::Query::Class->new( class => "KiokuDB::Test::Employee" );
sub bench_write {
    for ( 1 .. 20 ) {
        my $t = times;
        until ( times() - $t > 1 ) {
            for ( 1 .. 10 ) {
                my $s = $mxsd_hash->new_scope;
                my @objs = $f->create, $f->create;
                $mxsd_hash->store(@objs);
            }
        }
        $mxsd_hash->backend->clear;
        print ".";
        print " " if $_ % 5 == 0;
    }
    print "done\n";
}
sub bench_read {
    my @ids = do {
        my $s = $mxsd_hash->new_scope;
        $mxsd_hash->store($f->create, $f->create)
    };
    for ( 1 .. 20 ) {
        my $t = times;
        until ( times() - $t > 1 ) {
            for ( 1 .. 250 ) {
                my $s = $mxsd_hash->new_scope;
                my @objs = $mxsd_hash->lookup(@ids);
            }
        }
        print ".";
        print " " if $_ % 5 == 0;
    }
    print "done\n";
}
sub bench_search {
    use KiokuDB::GIN;
    use KiokuDB;
    use KiokuDB::Backend::Hash;
    use Search::GIN::Query::Class;
    use Search::GIN::Extract::Class;
    {
        package MyGIN;
        use Moose;
        extends qw(KiokuDB::Backend::Hash);
        with (
            qw(
            KiokuDB::GIN
            Search::GIN::Driver::Hash
            Search::GIN::Extract::Delegate
            ),
        );
        __PACKAGE__->meta->make_immutable;
    }
    my $gin = MyGIN->new(
        extract => Search::GIN::Extract::Class->new,
        root_only => 0,
    );
    my $dir = KiokuDB->new(
        backend => $gin,
    );
    for ( 1 .. 10 ) {
        my $s = $dir->new_scope;
        $dir->store($f->create);
    }
    my $q_employee = Search::GIN::Query::Class->new( class => "KiokuDB::Test::Employee" );
    for ( 1 .. 20 ) {
        my $t = times;
        until ( times() - $t > 1 ) {
            for ( 1 .. 10 ) {
                my $s = $dir->new_scope;
                $dir->search($q_employee);
            }
        }
        print ".";
        print " " if $_ % 5 == 0;
    }
    print "done\n";
}
#bench_read();
#bench_write();
bench_search();
 |