File: slow-sort.pl

package info (click to toggle)
libset-object-perl 1.42-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 620 kB
  • sloc: perl: 1,069; makefile: 14
file content (31 lines) | stat: -rw-r--r-- 769 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
#!/bin/env perl
use strict;
use warnings;
use List::Util qw/shuffle/;
use Set::Object 1.35 qw/set/;
my @list = shuffle(1..1000);
use Benchmark 'cmpthese';

my $lil_set = set(@list);
my $x = 0;
cmpthese(-3,
         {
           'Fast set->members' =>
             sub {
               foreach my $item ($lil_set->members()) {
                 $x += $item;
                 $x += $item;
                 $x += $item;
                 $x += $item;
                 $x += $item;
               }},
           'Slow @$set' => 
             sub {
               foreach my $item (@{$lil_set}) {
                 $x += $item;
                 $x += $item;
                 $x += $item;
                 $x += $item;
                 $x += $item;
               }}});
__END__