1 # Copyright (C) 2004-2009, Parrot Foundation.
6 bench_op - Benchmark one or more opcodes
10 parrot bench_op.pir 'add $I0, $I1, $I2'
11 parrot bench_op.pir --preops='newclass $P0, "Foo"' file_w_ops.pir
12 parrot bench_op.pir --help
16 The given opcode(s) are compiled into a sequence:
33 so they should conform to Parrot Calling Conventions.
34 The code gets executed with the PIR compiler - using symbolic variables is always ok.
36 Output is the time in seconds for 1.000.000 instruction(s).
44 Run the given opcode(s) in a loop I<N> time.
45 If no I<--times> options is given 100.000 is used.
49 Set I<--verbose> to 1 to see the total time.
50 Set I<--verbose> to 2 to see the compiled programs.
52 =item I<--preops='opcode(s)'>
54 Execute the given opcodes in front of the loop. This is needed for ops,
55 that have side effects like B<newclass>.
59 Print a short description and exit.
63 Print program version and exit.
69 .const string VERSION = "0.1.1"
74 load_bytecode "Getopt/Obj.pbc"
82 # Specification of command line arguments.
84 getopts = new "Getopt::Obj"
85 # getopts."notOptStop"(1)
86 push getopts, "version"
87 push getopts, "verbose=i"
89 push getopts, "times=i"
90 push getopts, "preops=s"
96 opt = getopts."get_options"(argv)
100 unless argc goto do_help
104 unless def goto do_help
105 def = defined opt["version"]
107 def = defined opt["help"]
109 def = defined opt["times"]
110 unless def goto default_times
113 def = defined opt["verbose"]
114 unless def goto default_verbose
115 verbose = opt["verbose"]
118 def = defined opt["preops"]
119 unless def goto default_preops
120 preops = opt["preops"]
122 _run( argv, times, verbose, preops)
134 print " [--help] [--version] [--verbose=i]] [--times=N] \\ \n"
135 print "\t[--preops='op(s)'] file | opcode\n"
136 print "\nRun opcode on commandline or from file <N> times.\n"
137 print "s. perldoc -F "
151 unless verbose goto no_v1
158 # op may be a file or an opcode - try to open it
163 unless def goto op_is_op
164 read op, F, 10000 # TODO use stat
168 empty = _bench(times, verbose, '', '')
169 unless verbose goto no_v2
176 test = _bench(times, verbose, op, preops)
178 unless verbose goto no_v3
188 print "Time for 1 million instructions: "
207 .local string entry_label
208 entry_label = "_entry" . ls
209 compreg compiler, "PIR" # TODO PASM option
210 prog = ".sub " . entry_label
211 prog = prog . "\n.param int N\n.local int i\nnull i\n"
213 prog = prog . "\nloop:\n"
215 prog = prog . "\ninc i\nlt i, N, loop\n.end\n"
216 if verbose < 2 goto no_v2
217 print "\n#---------\n"
221 compiled = compiler(prog)
225 find_global entry, entry_label
236 You can't use the variables I<i> and I<N> nor the labels I<loop:> and
237 I<_entry\d> in your opcodes.
241 Leopold Toetsch <lt@toetsch.at>
249 # vim: expandtab shiftwidth=4 ft=pir: