I have been trying to find the timing of following function that is used to find the address for the ZigBee
module connected on my serial port. But when I tried to find the timing using timeit.Timer()
method. It is not responding back the time required for execution.
from xbee import ZigBee
from timeit import TImer
import serial
def ByteToHex(bytestring):
return ''.join(["%02X" % ord(x) for x in bytestring]).strip()
def self_add_tx():
s = serial.Serial('COM12', 9600)
xb = ZigBee(s)
xb.send('at',
command='SH')
self_frame_h = xb.wait_read_frame()
self_addh = self_frame_h['parameter']
xb.send('at',
command='SL')
self_frame_l = xb.wait_read_frame()
s.close()
self_addl = self_frame_l['parameter']
self_add = self_addh + self_addl
return ByteToHex(self_add)
print Timer(self_add_tx()).timeit()
When I execute the program, it is giving me following error:
Traceback (most recent call last):
File "I:/HUB/Python_learning/gateway_url_pi/gateway_url_pi_865_mhz/test3.py", line 24, in <module>
print Timer(self_add_tx()).timeit()
File "C:\Python27\lib\timeit.py", line 129, in __init__
compile(setup + '\n' + stmt, dummy_src_name, "exec")
File "<timeit-src>", line 2
0013A20040EA6DEC
^
SyntaxError: invalid syntax
I am unable to umderstand the error. Does anyone know of this issue? My code works perfectly without this Timer.timeit()
.