Created
October 15, 2021 16:04
-
-
Save h3ik0th/021115640331dfa91909864e455e9a48 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
# comprehensions vs lambda-filters | |
t = time.perf_counter() | |
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
strLamb = filter(lambda d: ((d.endswith("urday") or d.endswith("unday")) and "Oc" in d), datstrlist) | |
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
tLamb = time.perf_counter() - t | |
print(f'{tLamb:.4f} sec') | |
t = time.perf_counter() | |
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
c = [d for d in datstrlist if ((d.endswith("urday") or d.endswith("unday")) and "Oc" in d)] | |
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
tComp = time.perf_counter() - t | |
print(f'{tComp:.4f} sec: comprehension vs lambda-filter: {100*(tComp/tLamb-1):.1f}%') | |
df = pd.DataFrame(list(zip(strLamb,c)), columns=("lambda","comprehension")) | |
df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment