Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import string, random, time
- def randString(size=10, chars=string.ascii_uppercase):
- return ''.join(random.choice(chars) for _ in range(size))
- def is_substring(a,b):
- found = False
- for x in range(len(b)):
- for i in range(len(a)):
- if x+i >= len(b):
- found = False
- break
- if a[i] == b[x+i]:
- found = True
- else:
- found = False
- break
- if found:
- break
- return found
- def default_is_substring(a,b):
- return a in b
- a = "CAT"
- xvals = np.arange(0,100,10)
- mine = []
- theirs = []
- for x in xvals:
- b = randString(x)
- starttime = time.time()
- is_substring(a,b)
- endtime = time.time()
- mine.append(endtime - starttime)
- starttime = time.time()
- default_is_substring(a,b)
- endtime = time.time()
- theirs.append(endtime - starttime)
- plt.plot(xvals,mine)
- plt.plot(xvals,theirs)
- plt.grid()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment