Skip to content

Commit ea52a88

Browse files
committed
Clase 10
1 parent 88016c6 commit ea52a88

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

timeit_pruebas.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import timeit
2+
3+
NUMERO = 10_000_000
4+
5+
6+
def suma_con_sum() -> int:
7+
return sum(range(NUMERO))
8+
9+
10+
def suma_con_for() -> int:
11+
total = 0
12+
for i in range(NUMERO):
13+
total += i
14+
return total
15+
16+
17+
print(f"Función: sum() {suma_con_sum()}")
18+
print(f"Función: for() {suma_con_for()}")
19+
print(f"Son iguales? {suma_con_sum() == suma_con_for()}")
20+
21+
22+
repeticiones = 10
23+
24+
tiempo_sum = timeit.timeit(suma_con_sum, number=repeticiones)
25+
timepo_for = timeit.timeit(suma_con_for, number=repeticiones)
26+
27+
print(f"Tiempo para sum {tiempo_sum:.6f}")
28+
print(f"Tiempo para for {timepo_for:.6f}")

0 commit comments

Comments
 (0)