8000 Add benchmark of Factory provider · GrxE/python-dependency-injector@b2b69b3 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit b2b69b3

Browse files
committed
Add benchmark of Factory provider
1 parent 883fc95 commit b2b69b3

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

docs/main/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ that were made in every particular version.
77
From version 0.7.6 *Dependency Injector* framework strictly
88
follows `Semantic versioning`_
99

10+
Development version
11+
-------------------
12+
- Add additional benchmark of ``Factory`` provider.
13+
1014
3.13.1
1115
------
1216
- Fix typo on "Chained Factories" pattern docs page.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

0 commit comments

Comments
 (0)
0