NAME Bencher::Scenario::BinarySearch - Benchmark binary searching Perl arrays VERSION This document describes version 0.002 of Bencher::Scenario::BinarySearch (from Perl distribution Bencher-Scenario-BinarySearch), released on 2021-04-21. SYNOPSIS To run benchmark with default option: % bencher -m BinarySearch To run module startup overhead benchmark: % bencher --module-startup -m BinarySearch For more options (dump scenario, list/include/exclude/add participants, list/include/exclude/add datasets, etc), see bencher or run "bencher --help". DESCRIPTION Packaging a benchmark script as a Bencher scenario makes it convenient to include/exclude/add participants/datasets (either via CLI or Perl code), send the result to a central repository, among others . See Bencher and bencher (CLI) for more details. BENCHMARKED MODULES Version numbers shown below are the versions used when running the sample benchmark. List::BinarySearch::PP 0.25 List::BinarySearch::XS 0.09 BENCHMARK PARTICIPANTS * List::BinarySearch::PP-10k-num (perl_code) Code template: List::BinarySearch::PP::binsearch(sub {$a <=> $b}, int(10_000*rand()), \@Bencher::Scenario::BinarySearch::ary_10k_num) * List::BinarySearch::XS-10k-num (perl_code) Code template: List::BinarySearch::XS::binsearch(sub {$a <=> $b}, int(10_000*rand()), \@Bencher::Scenario::BinarySearch::ary_10k_num) * List::BinarySearch::PP-10k-num-tie (perl_code) Code template: List::BinarySearch::PP::binsearch(sub {$a <=> $b}, int(10_000*rand()), \@Bencher::Scenario::BinarySearch::ary_10k_num_tie) * List::BinarySearch::PP-10k-str (perl_code) Code template: List::BinarySearch::PP::binsearch(sub {$a cmp $b}, $Bencher::Scenario::BinarySearch::ary_10k_str[(10_000*rand())], \@Bencher::Scenario::BinarySearch::ary_10k_str) * List::BinarySearch::XS-10k-str (perl_code) Code template: List::BinarySearch::XS::binsearch(sub {$a cmp $b}, $Bencher::Scenario::BinarySearch::ary_10k_str[(10_000*rand())], \@Bencher::Scenario::BinarySearch::ary_10k_str) * List::BinarySearch::PP-10k-str-tie (perl_code) Code template: List::BinarySearch::PP::binsearch(sub {$a cmp $b}, $Bencher::Scenario::BinarySearch::ary_10k_str[(10_000*rand())], \@Bencher::Scenario::BinarySearch::ary_10k_str_tie) SAMPLE BENCHMARK RESULTS Run on: perl: *v5.30.0*, CPU: *Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz (2 cores)*, OS: *GNU/Linux Ubuntu version 20.04*, OS kernel: *Linux version 5.3.0-64-generic*. Benchmark with default options ("bencher -m BinarySearch"): #table1# +------------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+ | participant | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples | +------------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+ | List::BinarySearch::PP-10k-str-tie | 28000 | 36 | 0.00% | 4056.39% | 1.2e-07 | 20 | | List::BinarySearch::PP-10k-num-tie | 31000 | 33 | 9.38% | 3699.79% | 1.1e-07 | 20 | | List::BinarySearch::PP-10k-str | 75000 | 13 | 167.29% | 1455.04% | 5.3e-08 | 20 | | List::BinarySearch::PP-10k-num | 91000 | 11 | 224.35% | 1181.45% | 2.7e-08 | 20 | | List::BinarySearch::XS-10k-str | 1010000 | 0.986 | 3510.35% | 15.12% | 4.2e-10 | 20 | | List::BinarySearch::XS-10k-num | 1200000 | 0.86 | 4056.39% | 0.00% | 1.2e-09 | 22 | +------------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+ Benchmark module startup overhead ("bencher -m BinarySearch --module-startup"): #table2# +------------------------+-----------+-------------------+-----------------------+-----------------------+---------+---------+ | participant | time (ms) | mod_overhead_time | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples | +------------------------+-----------+-------------------+-----------------------+-----------------------+---------+---------+ | List::BinarySearch::PP | 11.7 | 5.1 | 0.00% | 77.75% | 1e-05 | 20 | | List::BinarySearch::XS | 9.23 | 2.63 | 26.62% | 40.38% | 7.6e-06 | 20 | | perl -e1 (baseline) | 6.6 | 0 | 77.75% | 0.00% | 5.7e-05 | 20 | +------------------------+-----------+-------------------+-----------------------+-----------------------+---------+---------+ To display as an interactive HTML table on a browser, you can add option "--format html+datatables". BENCHMARK NOTES List::BinarySearch::XS is an order of magnitude faster, but does not support tied arrays. On my laptop, binary searching a tied array is about three times faster than binary searching a regular array. HOMEPAGE Please visit the project's homepage at . SOURCE Source repository is at . BUGS Please report any bugs or feature requests on the bugtracker website When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. AUTHOR perlancar COPYRIGHT AND LICENSE This software is copyright (c) 2021 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.