Single and multiple character change test

main
Bob Mottram 2020-09-03 19:52:18 +01:00
parent e584076aca
commit bbe414d3a6
1 changed files with 12 additions and 1 deletions

View File

@ -2101,7 +2101,7 @@ def testConstantTimeStringCheck():
end = time.time() end = time.time()
avTime1 = ((end - start) * 1000000 / itterations) avTime1 = ((end - start) * 1000000 / itterations)
# change characters and observe timing difference # change a single character and observe timing difference
start = time.time() start = time.time()
for timingTest in range(itterations): for timingTest in range(itterations):
constantTimeStringCheck('nnjfbefefbsnjsdnvbcueftqfeuqfbqefnjeniwufgy', constantTimeStringCheck('nnjfbefefbsnjsdnvbcueftqfeuqfbqefnjeniwufgy',
@ -2112,6 +2112,17 @@ def testConstantTimeStringCheck():
# time difference should be less than 10uS # time difference should be less than 10uS
assert timeDiffMicroseconds < 10 assert timeDiffMicroseconds < 10
# change multiple characters and observe timing difference
start = time.time()
for timingTest in range(itterations):
constantTimeStringCheck('nnjfbefefbsnjsdnvbcueftqfeuqfbqefnjeniwufgy',
'ano1befffbsn7sd3vbluef6qseuqfpqeznjgni9bfgi')
end = time.time()
avTime2 = ((end - start) * 1000000 / itterations)
timeDiffMicroseconds = abs(avTime2 - avTime1)
# time difference should be less than 10uS
assert timeDiffMicroseconds < 10
def runAllTests(): def runAllTests():
print('Running tests...') print('Running tests...')