Created
January 29, 2023 13:01
-
-
Save ronzhin-dmitry/4d88d51ab0917c03aa60a4fa904bff41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Worst case test of naive substring search | |
import time | |
needle = 'a'*1000 + 'b' #so we search for a string with 1000 times letter 'a' and one letter 'b' at the end | |
haystack = 'a'*10000 + 'b' #and the haystack is almost like this, but longer | |
result = [] | |
start = time.time() | |
for i in range(50): #we repeat 50 times just to better track time | |
result = search_naive(needle, haystack) | |
end = time.time() | |
print('Positions:',result) | |
print('Time elapsed:',end-start) | |
#Example output on my machine: | |
#Positions: [9000] | |
#Time elapsed: 94.60738587379456 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment