-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.pl
executable file
·50 lines (43 loc) · 990 Bytes
/
benchmark.pl
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(:all :hireswallclock);
use List::MoreUtils qw();
my @numbers = (1..10000);
my @list;
for my $i (1..1000000) {
push @list, int rand($#numbers);
}
my $count = 10;
Benchmark::cmpthese($count, {
'hash' => \&hash,
'uniq' => \&uniq,
'leap' => \&leap,
}, 'all');
sub hash {
my %tmp;
$tmp{$_} = 1 for @list;
my @result = keys %tmp;
return \@result;
}
sub uniq {
my @result = List::MoreUtils::uniq @list;
return \@result;
}
sub leap {
my $n = shift;
our $pid;
if (!$pid || $pid != $$) {
$pid = $$;
open my $pid_file, '>', '/sys/module/leap/parameters/pid' or die;
print $pid_file $pid;
close $pid_file;
}
open my $utime_file, '<', '/proc/driver/utime' or die;
my $utime = <$utime_file>;
close $utime_file;
uniq();
open $utime_file, '>', '/proc/driver/utime' or die;
print $utime_file $utime;
close $utime_file;
}