time measurement for exiConnector

This commit is contained in:
uhi22 2022-11-20 19:13:41 +01:00
parent ec789878ea
commit 6fd0f72666

View file

@ -93,6 +93,10 @@ else:
# Functions # Functions
def exiprint(s):
# todo: print to console or log or whatever
pass
def exiHexToByteArray(hexString): def exiHexToByteArray(hexString):
# input: a string with the two-byte-hex representation # input: a string with the two-byte-hex representation
# output: a byte array with the same data. # output: a byte array with the same data.
@ -176,7 +180,7 @@ def exiEncode(strMessageName):
# param1 = "Eh" # Eh for encode handshake, SupportedApplicationProtocolResponse # param1 = "Eh" # Eh for encode handshake, SupportedApplicationProtocolResponse
# param1 = "EDa" # EDa for Encode, Din, SessionSetupResponse # param1 = "EDa" # EDa for Encode, Din, SessionSetupResponse
param1 = strMessageName param1 = strMessageName
print("[EXICONNECTOR] exiEncode " + param1) exiprint("[EXICONNECTOR] exiEncode " + param1)
result = subprocess.run([pathToOpenV2GExe, param1], capture_output=True, text=True) result = subprocess.run([pathToOpenV2GExe, param1], capture_output=True, text=True)
if (len(result.stderr)>0): if (len(result.stderr)>0):
strConverterResult = "exiEncode ERROR. stderr:" + result.stderr strConverterResult = "exiEncode ERROR. stderr:" + result.stderr
@ -237,11 +241,32 @@ def testReadExiFromFile():
s = s.replace("\n", "") # Remove line feeds s = s.replace("\n", "") # Remove line feeds
#print(s) #print(s)
testDecoder(s, "DD", "") testDecoder(s, "DD", "")
def testTimeConsumption():
strHex = "809a001150400000c80006400000"
pre = "DD"
tStart = time.time()
nRuns = 100
for i in range(0, nRuns):
decoded=exiDecode(strHex, pre)
tStop = time.time()
elapsed_time = tStop - tStart
print("Decoder: Execution time for " + str(nRuns) + " runs:", elapsed_time, "seconds")
tStart = time.time()
nRuns = 100
for i in range(0, nRuns):
s = exiEncode("EDC_1122334455667788")
tStop = time.time()
elapsed_time = tStop - tStart
print("Encoder: Execution time for " + str(nRuns) + " runs:", elapsed_time, "seconds")
if __name__ == "__main__": if __name__ == "__main__":
nFail=0 nFail=0
print("Testing exiConnector...") print("Testing exiConnector...")
testTimeConsumption()
exit()
#testReadExiFromFile() #testReadExiFromFile()
#exit() #exit()
#testByteArrayConversion("123456") #testByteArrayConversion("123456")