The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Bencher::Scenario::PERLANCAR::pass_list_vs_array - Benchmark passing list vs array reference

VERSION

This document describes version 0.06 of Bencher::Scenario::PERLANCAR::pass_list_vs_array (from Perl distribution Bencher-Scenarios-PERLANCAR), released on 2017-01-25.

SYNOPSIS

To run benchmark with default option:

 % bencher -m PERLANCAR::pass_list_vs_array

For more options (dump scenario, list/include/exclude/add participants, list/include/exclude/add datasets, etc), see bencher or run bencher --help.

DESCRIPTION

Passing a large array by reference will generate a large saving only if we reuse the list (pass it multiple times).

BENCHMARK PARTICIPANTS

  • pass_list (perl_code)

    Code template:

     my $sub = sub {}; my @list = 1..<size>;  for (1..<reuse>) { $sub->(@list) }
  • pass_arrayref (perl_code)

    Code template:

     my $sub = sub {}; my @list = 1..<size>;  for (1..<reuse>) { $sub->(\@list) }

BENCHMARK DATASETS

  • data

SAMPLE BENCHMARK RESULTS

Run on: perl: v5.24.0, CPU: Intel(R) Core(TM) M-5Y71 CPU @ 1.20GHz (2 cores), OS: GNU/Linux LinuxMint version 17.3, OS kernel: Linux version 3.19.0-32-generic.

Benchmark with default options (bencher -m PERLANCAR::pass_list_vs_array):

 #table1#
 +---------------+-----------+----------+-----------+-------------+------------+-----------+---------+
 | participant   | arg_reuse | arg_size | rate (/s) |  time (ms)  | vs_slowest |  errors   | samples |
 +---------------+-----------+----------+-----------+-------------+------------+-----------+---------+
 | pass_list     | 1000      | 10000    |     32    | 31          |      1     |   0.00012 |      21 |
 | pass_list     | 100       | 10000    |    310    |  3.2        |      9.8   | 1.9e-05   |      20 |
 | pass_list     | 1000      | 1000     |    420    |  2.4        |     13     | 5.4e-06   |      22 |
 | pass_list     | 10        | 10000    |   1800    |  0.56       |     56     | 1.6e-06   |      20 |
 | pass_arrayref | 1000      | 10000    |   2710    |  0.369      |     84.7   | 2.1e-07   |      21 |
 | pass_list     | 1         | 10000    |   3300    |  0.3        |    100     | 4.3e-07   |      20 |
 | pass_list     | 1000      | 100      |   3330    |  0.301      |    104     | 2.1e-07   |      20 |
 | pass_arrayref | 10        | 10000    |   3750    |  0.267      |    117     | 2.1e-07   |      20 |
 | pass_list     | 100       | 1000     |   3900    |  0.26       |    120     | 1.1e-06   |      21 |
 | pass_arrayref | 1         | 10000    |   3953.09 |  0.252967   |    123.509 |   0       |      20 |
 | pass_arrayref | 100       | 10000    |   4010    |  0.249      |    125     | 2.1e-07   |      20 |
 | pass_arrayref | 1000      | 1000     |   7771.31 |  0.128678   |    242.805 | 4.6e-11   |      20 |
 | pass_arrayref | 1000      | 100      |   9970    |  0.1        |    311     | 2.5e-08   |      23 |
 | pass_list     | 10        | 1000     |  20000    |  0.05       |    600     | 9.2e-07   |      23 |
 | pass_arrayref | 100       | 1000     |  27000    |  0.037      |    840     |   5e-08   |      23 |
 | pass_list     | 100       | 100      |  32028.1  |  0.0312226  |   1000.68  | 1.2e-11   |      20 |
 | pass_list     | 1         | 1000     |  36000    |  0.027      |   1100     | 6.7e-08   |      20 |
 | pass_arrayref | 10        | 1000     |  37000    |  0.027      |   1200     | 5.3e-08   |      20 |
 | pass_arrayref | 1         | 1000     |  40000    |  0.025      |   1300     |   5e-08   |      23 |
 | pass_arrayref | 100       | 100      |  77724.5  |  0.012866   |   2428.41  | 1.1e-11   |      30 |
 | pass_list     | 10        | 100      | 167000    |  0.00599    |   5220     | 1.7e-09   |      20 |
 | pass_arrayref | 10        | 100      | 250000    |  0.0039     |   7900     | 6.7e-09   |      20 |
 | pass_list     | 1         | 100      | 333991    |  0.00299409 |  10435.1   |   0       |      22 |
 | pass_arrayref | 1         | 100      | 361000    |  0.00277    |  11300     | 8.3e-10   |      20 |
 +---------------+-----------+----------+-----------+-------------+------------+-----------+---------+

To display as an interactive HTML table on a browser, you can add option --format html+datatables.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Bencher-Scenarios-PERLANCAR.

SOURCE

Source repository is at https://github.com/perlancar/perl-Bencher-Scenarios-PERLANCAR.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Bencher-Scenarios-PERLANCAR

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 <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 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.