File: rand.pir

package info (click to toggle)
parrot 6.6.0-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,164 kB
  • ctags: 16,050
  • sloc: ansic: 110,715; perl: 94,382; yacc: 1,911; lex: 1,529; lisp: 1,163; cpp: 782; python: 646; ruby: 335; sh: 140; makefile: 129; cs: 49; asm: 30
file content (186 lines) | stat: -rw-r--r-- 3,543 bytes parent folder | download | duplicates (2)
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
176
177
178
179
180
181
182
183
184
185
186
# Copyright (C) 2009, Parrot Foundation.

=head1 NAME

examples/benchmarks/rand.pir - rand dynop benchmark

=head1 SYNOPSIS

    % time ./parrot examples/benchmarks/rand.pir [count]

=head1 DESCRIPTION

Times the computation of C<count> (default 1e8) random numbers using
the C<rand> dynop.

=cut

.loadlib 'math_ops'

.sub _main
    .param pmc argv

    .local int count
    count = 1e8

    .local int argc
    argc = argv
    if argc <= 1 goto no_arg
    $S0 = argv[1]
    count = $S0
no_arg:

    count /= 8

    .local num t0, t1, t2, t3, t4, t5, t6
    .local num r_num, min_num, max_num
    .local int r_int, min_int, max_int
    .local int i

    min_num = 1.0
    max_num = 20.0
    min_int = 1
    max_int = 20

    .local num tn0, tn1, tnull
    tn0 = time
    i = count
  null_loop_top:
    dec i
    if i > 0 goto null_loop_top
    tn1 = time
    tnull = tn1 - tn0

    t0 = time
    i = count
  t0_top:
    r_num = rand
    r_num = rand
    r_num = rand
    r_num = rand
    r_num = rand
    r_num = rand
    r_num = rand
    r_num = rand
    dec i
    if i > 0 goto t0_top

    t1 = time
    i = count
  t1_top:
    r_int = rand
    r_int = rand
    r_int = rand
    r_int = rand
    r_int = rand
    r_int = rand
    r_int = rand
    r_int = rand
    dec i
    if i > 0 goto t1_top

    t2 = time
    i = count
  t2_top:
    r_num = rand max_num
    r_num = rand max_num
    r_num = rand max_num
    r_num = rand max_num
    r_num = rand max_num
    r_num = rand max_num
    r_num = rand max_num
    r_num = rand max_num
    dec i
    if i > 0 goto t2_top

    t3 = time
    i = count
  t3_top:
    r_int = rand max_int
    r_int = rand max_int
    r_int = rand max_int
    r_int = rand max_int
    r_int = rand max_int
    r_int = rand max_int
    r_int = rand max_int
    r_int = rand max_int
    dec i
    if i > 0 goto t3_top

    t4 = time
    i = count
  t4_top:
    r_num = rand min_num, max_num
    r_num = rand min_num, max_num
    r_num = rand min_num, max_num
    r_num = rand min_num, max_num
    r_num = rand min_num, max_num
    r_num = rand min_num, max_num
    r_num = rand min_num, max_num
    r_num = rand min_num, max_num
    dec i
    if i > 0 goto t4_top

    t5 = time
    i = count
  t5_top:
    r_int = rand min_int, max_int
    r_int = rand min_int, max_int
    r_int = rand min_int, max_int
    r_int = rand min_int, max_int
    r_int = rand min_int, max_int
    r_int = rand min_int, max_int
    r_int = rand min_int, max_int
    r_int = rand min_int, max_int
    dec i
    if i > 0 goto t5_top

    t6 = time

    report('null loop  ', tn0, tn1, 0,   count)

    count *= 8

    report('num        ', t0, t1, tnull, count)
    report('int        ', t1, t2, tnull, count)
    report('num_max    ', t2, t3, tnull, count)
    report('int_max    ', t3, t4, tnull, count)
    report('num_min_max', t4, t5, tnull, count)
    report('int_min_max', t5, t6, tnull, count)
.end

.sub report
    .param string name
    .param num    start
    .param num    end
    .param num    null_time
    .param int    count

    .local num run_time
    run_time  = end - start
    run_time -= null_time
    if run_time > 0 goto time_ok
    run_time  = .000001
  time_ok:

    .local num per_second
    .local int ps
    per_second = count / run_time
    ps = per_second

    print name
    print ': '
    print ps
    print ' per second ('
    print count
    print ' / '
    print run_time
    print " seconds)\n"
.end


# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: