-
Notifications
You must be signed in to change notification settings - Fork 138
/
mops.pl
102 lines (80 loc) · 2.78 KB
/
mops.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! perl
# Copyright (C) 2001-2007, Parrot Foundation.
=head1 NAME
examples/benchmarks/mops.c - Calculate M ops/s
=head1 SYNOPSIS
% perl examples/benchmarks/mops.pl
=head1 DESCRIPTION
A Perl implementation of the F<examples/benchmarks/mops.pasm> example program,
for speed comparisons.
Calculates a value for M ops/s (million operations per second) using
integer arithmetic.
Prints out:
=over 4
=item * the number of look iterations,
=item * the estimated number of ops performed,
=item * the elapsed time, and
=item * the number of M op/s.
=back
=cut
use strict;
use warnings;
use vars qw( $I1 $I2 $I3 $I4 $I5 $N1 $N2 $N5 );
sub time_hires { return time() }
#$I2 = 0; # set I2, 0
$I3 = 1; # set I3, 1
$I4 = 10000000; # set I4, 10000000
#
print "Iterations: $I4\n"; # print "Iterations: "
# print I4
# print "\n"
#
$I1 = 2; # set I1, 2
$I5 = $I4 * $I1; # mul I5, I4, I1
#
print "Estimated ops: $I5\n"; # print "Estimated ops: "
# print I5
# print "\n"
#
$N1 = time_hires(); # time N1
#
REDO: # REDO:
$I4 = $I4 - $I3; # sub I4, I4, I3
goto REDO if $I4; # if I4, REDO
#
DONE: # DONE:
$N5 = time_hires(); # time N5
#
$N2 = $N5 - $N1; # sub N2, N5, N1
#
print "Elapsed time: $N2\n"; # print "Elapsed time: "
# print N2
# print "\n"
#
$N1 = $I5; # iton N1, I5
$N1 = $N1 / $N2; # div N1, N1, N2
$N2 = 1000000.0; # set N2, 1000000.0
$N1 = $N1 / $N2; # div N1, N1, N2
#
print "M op/s: $N1\n"; # print "M op/s: "
# print N1
# print "\n"
#
exit(0); # end
=head1 SEE ALSO
F<examples/benchmarks/mops.pasm>,
F<examples/mops/mops.c>,
F<examples/mops/mops.cs>,
F<examples/mops/mops.il>,
F<examples/mops/mops.p6>,
F<examples/mops/mops.ps>,
F<examples/mops/mops.py>,
F<examples/mops/mops.rb>,
F<examples/mops/mops.scheme>.
=cut
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: