Created
January 30, 2023 13:24
-
-
Save ronzhin-dmitry/15f933c58c8157a20583053fc45d00e1 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
#Just the same worst-case test as for naive case. But now we will have a much better time complexity | |
import time | |
needle = 'a'*1000 + 'b' | |
haystack = 'a'*10000 + 'b' | |
result = [] | |
start = time.time() | |
buf_memory = [0] * (len(needle) + len(haystack) + 1) | |
start2 = time.time() | |
for i in range(50): | |
result = search_z_func(needle, haystack, buf_memory) | |
end = time.time() | |
print('Positions:',result) | |
print('Time elapsed (with mem-alloc):',end-start) | |
print('Time elapsed (search only):',end-start2) | |
#Example output: | |
#Positions: [9000] | |
#Time elapsed (with mem-alloc): 1.3396055698394775 | |
#Time elapsed (search only): 1.3396055698394775 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment