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 467de6c commit 7b5a231Copy full SHA for 7b5a231
example.py
@@ -3,31 +3,31 @@
3
4
5
def factorial(n):
6
- if n <= 0:
7
- return 0
8
- if n == 1:
+ assert n >= 0
+ if n == 0 or n == 1:
9
return 1
10
return n * factorial(n - 1)
11
12
13
@cached()
14
def quick_factorial(n):
15
16
17
18
19
return n * quick_factorial(n - 1)
20
21
22
def test1():
23
- factorial(100)
+ for i in range(1, 100):
+ factorial(i)
24
25
26
def test2():
27
- quick_factorial(100)
+ quick_factorial(i)
28
29
30
-test_times = 100000
+test_times = 1000
31
time1 = timeit.timeit(test1, number=test_times) / test_times
32
time2 = timeit.timeit(test2, number=test_times) / test_times
33
0 commit comments