/
float4.pir
175 lines (141 loc) · 3.7 KB
/
float4.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Copyright (C) 2008-2009, Parrot Foundation.
=head1 TITLE
float4.pir - Benchmark different ways of filling a float4 struct
=head1 SYNOPSIS
$ cd parrot-home
$ ./parrot examples/benchmarks/float4.pir
=head1 DESCRIPTION
This benchmark compares 5 different ways of defining and filling a float4
structure (a common vector length, especially for graphics).
=cut
.include 'datatypes.pasm'
.sub main :main
.param pmc argv
# count = argv[1] || 1_000_000
.local int count
$S0 = argv[1]
count = $S0
if count goto make_struct_defs
count = 1000000
# Create variant structure definitions
make_struct_defs:
.local pmc struct, named_struct, array, named_array
struct = new 'ResizablePMCArray'
push struct, .DATATYPE_FLOAT
push struct, 0
push struct, 0
push struct, .DATATYPE_FLOAT
push struct, 0
push struct, 0
push struct, .DATATYPE_FLOAT
push struct, 0
push struct, 0
push struct, .DATATYPE_FLOAT
push struct, 0
push struct, 0
named_struct = new 'OrderedHash'
named_struct['a'] = .DATATYPE_FLOAT
push named_struct, 0
push named_struct, 0
named_struct['b'] = .DATATYPE_FLOAT
push named_struct, 0
push named_struct, 0
named_struct['c'] = .DATATYPE_FLOAT
push named_struct, 0
push named_struct, 0
named_struct['d'] = .DATATYPE_FLOAT
push named_struct, 0
push named_struct, 0
array = new 'ResizablePMCArray'
push array, .DATATYPE_FLOAT
push array, 4
push array, 0
named_array = new 'OrderedHash'
named_array['a'] = .DATATYPE_FLOAT
push named_array, 4
push named_array, 0
# Locals used for each timing loop
.local num start, stop, elapsed
.local pmc float4
.local int i
# Time named struct elements treated as array
float4 = new 'ManagedStruct', named_struct
i = count
start = time
named_struct_array_loop:
float4[0] = start
float4[1] = start
float4[2] = start
float4[3] = start
dec i
if i goto named_struct_array_loop
stop = time
elapsed = stop - start
print 'Array Struct: '
say elapsed
# Time struct element per array element
float4 = new 'ManagedStruct', struct
i = count
start = time
struct_loop:
float4[0] = start
float4[1] = start
float4[2] = start
float4[3] = start
dec i
if i goto struct_loop
stop = time
elapsed = stop - start
print ' Struct: '
say elapsed
# Time *named* struct element per array element
float4 = new 'ManagedStruct', named_struct
i = count
start = time
named_struct_loop:
float4['a'] = start
float4['b'] = start
float4['c'] = start
float4['d'] = start
dec i
if i goto named_struct_loop
stop = time
elapsed = stop - start
print 'Named Struct: '
say elapsed
# Time array packed into first element of struct
float4 = new 'ManagedStruct', array
i = count
start = time
array_loop:
float4[0;0] = start
float4[0;1] = start
float4[0;2] = start
float4[0;3] = start
dec i
if i goto array_loop
stop = time
elapsed = stop - start
print ' Array: '
say elapsed
# Time array packed into *named* first element of struct
float4 = new 'ManagedStruct', named_array
i = count
start = time
named_array_loop:
float4['a';0] = start
float4['a';1] = start
float4['a';2] = start
float4['a';3] = start
dec i
if i goto named_array_loop
stop = time
elapsed = stop - start
print 'Named Array: '
say elapsed
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: