-
-
Save yuce/cadd9b39a06bee679b75454004d520aa to your computer and use it in GitHub Desktop.
Revisions
-
yuce created this gist
Jun 1, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,91 @@ import time dv = { 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10, 10: 11, 11: 12, 12: 13, 13: 14, 14: 15, 15: 16, 16: 17, 17: 18, 18: 19, 19: 20, } def d1(x): v = dv.get(x) if v is None: return 0 return v def d2(x): if x == 1: return 2 elif x == 2: return 3 elif x == 4: return 5 elif x == 5: return 6 elif x == 6: return 7 elif x == 7: return 8 elif x == 8: return 9 elif x == 9: return 10 elif x == 10: return 11 elif x == 11: return 12 elif x == 12: return 13 elif x == 13: return 14 elif x == 14: return 15 elif x == 15: return 16 elif x == 16: return 17 elif x == 17: return 18 elif x == 18: return 19 elif x == 19: return 20 return 0 def measure(f, times): c = 0 tic = time.time() for i in range(times): c += f(i) toc = time.time() return (toc - tic)*1000 def main(): n = 100_000 d1_took = measure(d1, n) d2_took = measure(d2, n) print(f"d1: {d1_took}") print(f"d2: {d2_took}") if __name__ == '__main__': main()