-
Notifications
You must be signed in to change notification settings - Fork 2
/
array_access.pir
121 lines (96 loc) · 2.41 KB
/
array_access.pir
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Copyright (C) 2001-2014, Parrot Foundation.
=head1 NAME
examples/benchmarks/array_access.pir - benchmark reading from an array
=head1 SYNOPSIS
./parrot examples/benchmarks/array_access.pir --arr-size=2000
=head1 DESCRIPTION
Inspired by computer language shootout.
=cut
.sub 'main' :main
.param pmc argv
# name of the program
.local string program_name
program_name = shift argv
.local int arr_size
arr_size = 128
_bench( 'FixedFloatArray', arr_size )
_bench( 'FixedIntegerArray', arr_size )
_bench( 'FixedPMCArray', arr_size )
_bench( 'FixedStringArray', arr_size )
_bench( 'ResizableFloatArray', arr_size )
_bench( 'ResizableIntegerArray', arr_size )
_bench( 'ResizablePMCArray', arr_size )
_bench( 'ResizableStringArray', arr_size )
_bench( 'FixedPMCArray', arr_size )
.end
=head2 void bench( int arr_class, int arr_size )
=cut
.sub _bench
.param string arr_class
.param int arr_size
# Two arrays with fixed size
.local pmc arr_1, arr_2
arr_1 = new arr_class
arr_1 = arr_size
arr_2 = new arr_class
arr_2 = arr_size
.local num start_time
start_time = time
# initialize arr_1 and arr_2
.local int x_index, value
x_index = 0
value = 1
X_LOOP:
if x_index >= arr_size goto X_DONE
arr_1[x_index] = value
arr_2[x_index] = 0
inc x_index
inc value
goto X_LOOP
X_DONE:
.local int max_index, z_index, y_index
max_index = arr_size - 1
y_index = 0
Y_LOOP: # 1000 iterations
if y_index >= 1000 goto Y_DONE
z_index = max_index
Z_LOOP: # arr_size iterations
if z_index < 0 goto Z_DONE
set $I3, arr_2[z_index]
set $I4, arr_1[z_index]
add $I3, $I4
arr_2[z_index] = $I3
dec z_index
branch Z_LOOP
Z_DONE:
inc y_index
branch Y_LOOP
Y_DONE:
# final output
print "1 * 1000 = "
value = arr_2[0]
print value
print "\n"
print arr_size
print " * 1000 = "
value = arr_2[max_index]
print value
print "\n"
.local num start_time, end_time, span_time
end_time = time
span_time = end_time - start_time
.local string arr_type
arr_type = typeof arr_1
print arr_type
print ": "
print span_time
print "s\n\n"
.end
=head1 SEE ALSO
Computer language shootout. L<http://shootout.alioth.debian.org>
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: