Skip to content

Commit

Permalink
[examples] new benchmark for rand dynop
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/trunk@40555 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
Geoff Broadwell (japhb) committed Aug 15, 2009
1 parent d98f11b commit 56e94e6
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 3 deletions.
7 changes: 4 additions & 3 deletions MANIFEST
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
# generated by tools/dev/mk_manifest_and_skip.pl Thu Aug 13 02:35:20 2009 UT
# generated by tools/dev/mk_manifest_and_skip.pl Sat Aug 15 07:51:12 2009 UT
#
# See below for documentation on the format of this file.
#
Expand Down Expand Up @@ -626,6 +626,7 @@ examples/benchmarks/primes2.py [examples]
examples/benchmarks/primes2.rb [examples]
examples/benchmarks/primes2_i.pir [examples]
examples/benchmarks/primes_i.pasm [examples]
examples/benchmarks/rand.pir [examples]
examples/benchmarks/stress.pasm [examples]
examples/benchmarks/stress.pl [examples]
examples/benchmarks/stress.rb [examples]
Expand Down Expand Up @@ -1247,8 +1248,8 @@ src/datatypes.c []
src/debug.c []
src/dynext.c []
src/dynoplibs/README []doc
src/dynoplibs/obscure.ops []
src/dynoplibs/math.ops []
src/dynoplibs/obscure.ops []
src/dynpmc/README.pod []doc
src/dynpmc/dynlexpad.pmc [devel]src
src/dynpmc/ext.pir []
Expand Down Expand Up @@ -1674,8 +1675,8 @@ t/configure/testlib/verbosefoobar [test]
t/distro/file_metadata.t [test]
t/distro/manifest.t [test]
t/distro/meta_yml.t [test]
t/dynoplibs/obscure.t [test]
t/dynoplibs/math.t [test]
t/dynoplibs/obscure.t [test]
t/dynpmc/dynlexpad.t [test]
t/dynpmc/foo.t [test]
t/dynpmc/foo2.t [test]
Expand Down
187 changes: 187 additions & 0 deletions examples/benchmarks/rand.pir
@@ -0,0 +1,187 @@
# Copyright (C) 2009, Parrot Foundation.
# $Id$

=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:

0 comments on commit 56e94e6

Please sign in to comment.