File tree Expand file tree Collapse file tree 2 files changed +94
-0
lines changed Expand file tree Collapse file tree 2 files changed +94
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ that were made in every particular version.
7
7
From version 0.7.6 *Dependency Injector * framework strictly
8
8
follows `Semantic versioning `_
9
9
10
+ Development version
11
+ -------------------
12
+ - Add additional benchmark of ``Factory `` provider.
13
+
10
14
3.13.1
11
15
------
12
16
- Fix typo on "Chained Factories" pattern docs page.
Original file line number Diff line number Diff line change
1
+ """Dependency Injector Factory providers benchmark."""
2
+
3
+ import time
4
+
5
+ from dependency_injector import providers
6
+
7
+
8
+ N = 1000000
9
+
10
+
11
+ class A (object ):
12
+ pass
13
+
14
+
15
+ class B (object ):
16
+ pass
17
+
18
+
19
+ class C (object ):
20
+ pass
21
+
22
+
23
+ class Test (object ):
24
+ def __init__ (self , a , b , c ):
25
+ self .a = a
26
+ self .b = b
27
+ self .c = c
28
+
29
+
30
+ # Testing Factory provider
31
+
32
+ test_factory_provider = providers .Factory (
33
+ Test ,
34
+ a = providers .Factory (A ),
35
+ b = providers .Factory (B ),
36
+ c = providers .Factory (C ),
37
+ )
38
+
39
+ start = time .time ()
40
+ for _ in range (1 , N ):
41
+ test_factory_provider ()
42
+ finish = time .time ()
43
+
44
+ print (finish - start )
45
+
46
+
47
+ # Testing simple analog
48
+
49
+ def test_simple_factory_provider ():
50
+ return Test (a = A (), b = B (), c = C ())
51
+
52
+
53
+ start = time .time ()
54
+ for _ in range (1 , N ):
55
+ test_simple_factory_provider ()
56
+ finish = time .time ()
57
+
58
+ print (finish - start )
59
+
60
+ # ------
61
+ # Result
62
+ # ------
63
+ #
64 + # Python 2.7
65
+ #
66
+ # $ python tests/performance/factory_benchmark_1.py
67
+ # 0.87456202507
68
+ # 0.879760980606
69
+ #
70
+ # $ python tests/performance/factory_benchmark_1.py
71
+ # 0.949290990829
72
+ # 0.853044986725
73
+ #
74
+ # $ python tests/performance/factory_benchmark_1.py
75
+ # 0.964688062668
76
+ # 0.857432842255
77
+ #
78
+ # Python 3.7.0
79
+ #
80
+ # $ python tests/performance/factory_benchmark_1.py
81
+ # 1.1037120819091797
82
+ # 0.999565839767456
83
+ #
84
+ # $ python tests/performance/factory_benchmark_1.py
85
+ # 1.0855588912963867
86
+ # 1.0008318424224854
87
+ #
88
+ # $ python tests/performance/factory_benchmark_1.py
89
+ # 1.0706679821014404
90
+ # 1.0106139183044434
You can’t perform that action at this time.
0 commit comments