| 1 | package Bencher::Scenario::RandomLineModules; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $DATE = '2017-07-10'; # DATE | |||||||||
| 4 | 1 | our $VERSION = '0.05'; # VERSION | |||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Log::ger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub _create_file { | ||||||||
|
Subroutine
_create_file: not called CC=2 SCAR=17.9
| |||||||||||
| 12 | 0 | my ($num_lines) = @_; | |||||||||
| 13 | |||||||||||
| 14 | 0 | require File::Temp; | |||||||||
| 15 | 0 | my ($fh, $filename) = File::Temp::tempfile(); | |||||||||
| 16 | 0 | for (1..$num_lines) { | |||||||||
| 17 | 0 | print $fh sprintf("%049d\n", $_); | |||||||||
| 18 | } | ||||||||||
| 19 | 0 | $filename; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | our $scenario = { | ||||||||||
| 23 | summary => 'Benchmark modules which pick random line(s) from a file', | ||||||||||
| 24 | participants => [ | ||||||||||
| 25 | { | ||||||||||
| 26 | fcall_template => 'File::Random::Pick::random_line(<filename>)', | ||||||||||
| 27 | }, | ||||||||||
| 28 | { | ||||||||||
| 29 | module => 'File::RandomLine', | ||||||||||
| 30 | code_template => 'my $rl = File::RandomLine->new(<filename>); $rl->next', | ||||||||||
| 31 | }, | ||||||||||
| 32 | ], | ||||||||||
| 33 | |||||||||||
| 34 | datasets => [ | ||||||||||
| 35 | {name=>'1k_line' , _lines=>1_000 , args=>{filename=>undef}}, | ||||||||||
| 36 | {name=>'10k_line' , _lines=>10_000 , args=>{filename=>undef}}, | ||||||||||
| 37 | {name=>'100k_line', _lines=>100_000 , args=>{filename=>undef}, include_by_default=>0}, | ||||||||||
| 38 | {name=>'1M_line' , _lines=>1_000_000 , args=>{filename=>undef}, include_by_default=>0}, | ||||||||||
| 39 | {name=>'10M_line' , _lines=>10_000_000, args=>{filename=>undef}, include_by_default=>0}, | ||||||||||
| 40 | ], | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | before_gen_items => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 43 | 0 | my %args = @_; | |||||||||
| 44 | 0 | my $sc = $args{scenario}; | |||||||||
| 45 | |||||||||||
| 46 | 0 | my $dss = $sc->{datasets}; | |||||||||
| 47 | 0 | for my $ds (@$dss) { | |||||||||
| 48 | 0 | log_info("Creating temporary file with %d lines ...", $ds->{_lines}); | |||||||||
| 49 | 0 | my $filename = _create_file($ds->{_lines}); | |||||||||
| 50 | 0 | log_info("Created file %s", $filename); | |||||||||
| 51 | 0 | $ds->{args}{filename} = $filename; | |||||||||
| 52 | } | ||||||||||
| 53 | }, | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | before_return => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 56 | 0 | my %args = @_; | |||||||||
| 57 | 0 | my $sc = $args{scenario}; | |||||||||
| 58 | |||||||||||
| 59 | 0 | my $dss = $sc->{datasets}; | |||||||||
| 60 | 0 | for my $ds (@$dss) { | |||||||||
| 61 | 0 | my $filename = $ds->{args}{filename}; | |||||||||
| 62 | 0 | ▶ | next unless $filename; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | log_info("Unlinking %s", $filename); | |||||||||
| 64 | 0 | unlink $filename; | |||||||||
| 65 | } | ||||||||||
| 66 | }, | ||||||||||
| 67 | 1 | }; | |||||||||
| 68 | |||||||||||
| 69 | 1 | 1; | |||||||||
| 70 | # ABSTRACT: Benchmark modules which pick random line(s) from a file | ||||||||||
| 71 | |||||||||||
| 72 | __END__ | ||||||||||