/
addit.pl
46 lines (35 loc) · 896 Bytes
/
addit.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
#! perl -w
# Copyright (C) 2001-2003 The Perl Foundation. All rights reserved.
# $Id$
=head1 NAME
examples/benchmarks/addit.pl - Variable Argument Subroutines
=head1 SYNOPSIS
% time perl examples/benchmarks/addit.pl
=head1 DESCRIPTION
Joe Wilson's original Perl version of his C<varargs> subroutines
benchmark. It calls an "add it" function 500000 times in a loop and
prints the result (21001097.97).
=cut
use strict;
sub varargs_adder {
my $sum = 0;
for (my $a = $#_; $a >= 0; --$a) {
$sum += $_[$a];
}
return $sum
}
my $result = 0;
my @args;
$args[0] = 1000;
$args[1] = 7.100;
$args[2] = 87;
$args[3] = "3.87";
$args[4] = "21000000";
for (my $x = 500000; $x >= 0; --$x) {
$result = varargs_adder(@args);
}
print "$result\n";
=head1 SEE ALSO
F<examples/benchmarks/addit.pasm>, F<examples/benchmarks/addit.imc>,
F<examples/benchmarks/addit2.imc>.
=cut