Created
October 13, 2022 19:41
-
-
Save perfecto25/c70bb17c7dbdbdaeea435ea07719622d to your computer and use it in GitHub Desktop.
Py benchmarks
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 characters
from functools import reduce | |
import time | |
numbers = list(range(51000000)) | |
def add(numbers): | |
total = 0 | |
for n in numbers: | |
total += n | |
return total | |
print("\nusing Function") | |
start = time.time() | |
print(f"total: {add(numbers)}") | |
end = time.time() | |
print(f"time in sec: {end-start}") | |
print("\nusing builtin Sum funcion") | |
start = time.time() | |
print(f"total: {sum(numbers)}") | |
end = time.time() | |
print(f"time in sec: {end-start}") | |
print("\nusing lambda") | |
start = time.time() | |
print(f"total: {reduce(lambda x,y: x+y, numbers)}") | |
end = time.time() | |
print(f"time in sec: {end-start}") | |
print("\nusing lambda with dunder method") | |
start = time.time() | |
print(f"total: {reduce(lambda x,y: x.__add__(y), numbers)}") | |
end = time.time() | |
print(f"time in sec: {end-start}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment