We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 88016c6 commit ea52a88Copy full SHA for ea52a88
timeit_pruebas.py
@@ -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