1.1 --- a/rsvp.py Fri Feb 26 01:56:26 2010 +0100
1.2 +++ b/rsvp.py Wed Mar 03 00:26:00 2010 +0100
1.3 @@ -97,7 +97,11 @@
1.4 self.pc = pc or 0
1.5 self.debug = debug
1.6 self.abort_upon_exception = abort_upon_exception
1.7 +
1.8 + # Profiling.
1.9 +
1.10 self.counter = 0
1.11 + self.cost = 0
1.12
1.13 # Stacks.
1.14
1.15 @@ -262,6 +266,7 @@
1.16 print "At address", self.pc
1.17 else:
1.18 print "successfully."
1.19 + print "After", self.counter, "instructions at cost", self.cost, "units."
1.20
1.21 def test(self, module):
1.22
1.23 @@ -333,11 +338,13 @@
1.24 raise IllegalInstruction, (self.pc, instruction_name)
1.25 return method
1.26
1.27 - def perform(self, instruction):
1.28 + def perform(self, instruction, is_input=0):
1.29
1.30 "Perform the 'instruction', returning the next PC value or None."
1.31
1.32 - self.counter += 1
1.33 + if not is_input:
1.34 + self.counter += 1
1.35 + self.cost += instruction.cost
1.36 self.operand = instruction.get_operand()
1.37 method = self.get_method(instruction)
1.38 return method()
1.39 @@ -352,11 +359,11 @@
1.40
1.41 value = self.value
1.42 if self.instruction.source is not None:
1.43 - self.perform(self.instruction.source)
1.44 + self.perform(self.instruction.source, 1)
1.45 self.source = self.value
1.46 self.value = value
1.47 if self.instruction.input is not None:
1.48 - self.perform(self.instruction.input)
1.49 + self.perform(self.instruction.input, 1)
1.50
1.51 def jump(self, addr, next):
1.52