tagged release 0.6.4
[parrot.git] / examples / benchmarks / float4.pir
blob8037114c6f4ea45ddeb57d5dd23a4c3a3477856d
1 =head1 TITLE
3 float4.pir - Benchmark different ways of filling a float4 struct
5 =head1 SYNOPSIS
7     $ cd parrot-home
8     $ ./parrot examples/benchmarks/float4.pir
10 =head1 DESCRIPTION
12 This benchmark compares 4 different ways of defining and filling a float4
13 structure (a common vector length, especially for graphics).
15 =cut
18 .include 'datatypes.pasm'
20 .sub main :main
21     .param pmc argv
23     # count = argv[1] || 1_000_000
24     .local int count
25     $S0 = argv[1]
26     count = $S0
27     if count goto make_struct_defs
28     count = 1000000
30     # Create variant structure definitions
31   make_struct_defs:
32     .local pmc struct, named_struct, array, named_array
34     struct = new 'ResizablePMCArray'
35     push struct, .DATATYPE_FLOAT
36     push struct, 0
37     push struct, 0
38     push struct, .DATATYPE_FLOAT
39     push struct, 0
40     push struct, 0
41     push struct, .DATATYPE_FLOAT
42     push struct, 0
43     push struct, 0
44     push struct, .DATATYPE_FLOAT
45     push struct, 0
46     push struct, 0
48     named_struct = new 'OrderedHash'
49     named_struct['a'] = .DATATYPE_FLOAT
50     push named_struct, 0
51     push named_struct, 0
52     named_struct['b'] = .DATATYPE_FLOAT
53     push named_struct, 0
54     push named_struct, 0
55     named_struct['c'] = .DATATYPE_FLOAT
56     push named_struct, 0
57     push named_struct, 0
58     named_struct['d'] = .DATATYPE_FLOAT
59     push named_struct, 0
60     push named_struct, 0
62     array = new 'ResizablePMCArray'
63     push array, .DATATYPE_FLOAT
64     push array, 4
65     push array, 0
67     named_array = new 'OrderedHash'
68     named_array['a'] = .DATATYPE_FLOAT
69     push named_array, 4
70     push named_array, 0
72     # Locals used for each timing loop
73     .local num start, stop, elapsed
74     .local pmc float4
75     .local int i
77     # Time struct element per array element
78     float4  = new 'ManagedStruct', struct
79     i       = count
80     start   = time
82   struct_loop:
83     float4[0] = start
84     float4[1] = start
85     float4[2] = start
86     float4[3] = start
87     dec i
88     if i goto struct_loop
90     stop    = time
91     elapsed = stop - start
92     print '      Struct: '
93     say elapsed
95     # Time *named* struct element per array element
96     float4  = new 'ManagedStruct', named_struct
97     i       = count
98     start   = time
100   named_struct_loop:
101     float4['a'] = start
102     float4['b'] = start
103     float4['c'] = start
104     float4['d'] = start
105     dec i
106     if i goto named_struct_loop
108     stop    = time
109     elapsed = stop - start
110     print 'Named Struct: '
111     say elapsed
113     # Time array packed into first element of struct
114     float4  = new 'ManagedStruct', array
115     i       = count
116     start   = time
118   array_loop:
119     float4[0;0] = start
120     float4[0;1] = start
121     float4[0;2] = start
122     float4[0;3] = start
123     dec i
124     if i goto array_loop
126     stop    = time
127     elapsed = stop - start
128     print '       Array: '
129     say elapsed
131     # Time array packed into *named* first element of struct
132     float4  = new 'ManagedStruct', named_array
133     i       = count
134     start   = time
136   named_array_loop:
137     float4['a';0] = start
138     float4['a';1] = start
139     float4['a';2] = start
140     float4['a';3] = start
141     dec i
142     if i goto named_array_loop
144     stop    = time
145     elapsed = stop - start
146     print 'Named  Array: '
147     say elapsed
148 .end
151 # Local Variables:
152 #   mode: pir
153 #   fill-column: 100
154 # End:
155 # vim: expandtab shiftwidth=4 ft=pir: