[svn:parrot] r40555 - in trunk: . examples/benchmarks

japhb at svn.parrot.org japhb at svn.parrot.org
Sat Aug 15 07:52:33 UTC 2009


Author: japhb
Date: Sat Aug 15 07:52:31 2009
New Revision: 40555
URL: https://trac.parrot.org/parrot/changeset/40555

Log:
[examples] new benchmark for rand dynop

Added:
   trunk/examples/benchmarks/rand.pir   (contents, props changed)
Modified:
   trunk/MANIFEST

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	Sat Aug 15 05:48:08 2009	(r40554)
+++ trunk/MANIFEST	Sat Aug 15 07:52:31 2009	(r40555)
@@ -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.
 #
@@ -626,6 +626,7 @@
 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]
@@ -1247,8 +1248,8 @@
 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                                          []
@@ -1674,8 +1675,8 @@
 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]

Added: trunk/examples/benchmarks/rand.pir
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/examples/benchmarks/rand.pir	Sat Aug 15 07:52:31 2009	(r40555)
@@ -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:


More information about the parrot-commits mailing list