-
Notifications
You must be signed in to change notification settings - Fork 171
/
bench_presentation.py
191 lines (162 loc) · 6.66 KB
/
bench_presentation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""Performance tests for the presentation module."""
from copy import deepcopy
from pydicom._uid_dict import UID_dictionary
from pydicom.uid import UID
from pynetdicom import StoragePresentationContexts, build_context
from pynetdicom.presentation import (
PresentationContext,
negotiate_as_acceptor,
negotiate_as_requestor
)
class TimePresentationContext:
def setup(self):
self.contexts = []
for x in range(500):
cx = PresentationContext()
cx.context_id = 1
cx.abstract_syntax = '1.2.840.10008.5.1.4.1.1.2'
cx.transfer_syntax = ['1.2.840.10008.1.2',
'1.2.840.10008.1.2.1',
'1.2.840.10008.1.2.2']
self.contexts.append(cx)
def time_create_single_transfer_syntax(self):
"""Time creating contexts with a single transfer syntax"""
for x in range(500):
cx = PresentationContext()
cx.context_id = 1
cx.abstract_syntax = '1.2.840.10008.5.1.4.1.1.2'
cx.transfer_syntax = ['1.2.840.10008.1.2']
def time_create_double_transfer_syntax(self):
"""Time creating context with two transfer syntaxes."""
for x in range(500):
cx = PresentationContext()
cx.context_id = 1
cx.abstract_syntax = '1.2.840.10008.5.1.4.1.1.2'
cx.transfer_syntax = ['1.2.840.10008.1.2', '1.2.840.10008.1.2.1']
def time_create_triple_transfer_syntax(self):
"""Time creating context with three transfer syntaxes."""
for x in range(500):
cx = PresentationContext()
cx.context_id = 1
cx.abstract_syntax = '1.2.840.10008.5.1.4.1.1.2'
cx.transfer_syntax = ['1.2.840.10008.1.2',
'1.2.840.10008.1.2.1',
'1.2.840.10008.1.2.2']
def time_create_from_sop(self):
"""Test the time taken to create a PresentationContext from every
available standard DICOM UID.
"""
for uid in UID_dictionary:
cx = PresentationContext()
cx.context_id = 1
cx.abstract_syntax = uid
cx.transfer_syntax = ['1.2.840.10008.1.2',
'1.2.840.10008.1.2.1',
'1.2.840.10008.1.2.2']
class TimePresentationAcceptorRoleNegotiation(object):
"""Time presentation context negotiation as acceptor with SCP/SCU Role
Selection
"""
def setup(self):
# Requestor presentation contexts - max 126
self.requestor_contexts = []
for ii, cx in enumerate(StoragePresentationContexts):
cx.context_id = ii * 2 + 1
cx.scp_role = True
cx.scu_role = True
self.requestor_contexts.append(cx)
# Acceptor presentation contexts - no max
self.acceptor_contexts = []
for uid in UID_dictionary:
cx = PresentationContext()
cx.abstract_syntax = uid
cx.transfer_syntax = ['1.2.840.10008.1.2',
'1.2.840.10008.1.2.1',
'1.2.840.10008.1.2.2']
self.acceptor_contexts.append(cx)
self.ac_roles = {uid : (True, False) for uid in UID_dictionary}
def time_ps_ac_role(self):
"""Time a presentation service with SCP/SCU role negotiation."""
for ii in range(100):
negotiate_as_requestor(
self.requestor_contexts,
self.acceptor_contexts,
self.ac_roles
)
class TimePresentationRequestorRoleNegotiation(object):
"""Time presentation context negotiation as requestor with SCP/SCU Role
Selection
"""
def setup(self):
# Requestor presentation contexts - max 126
self.requestor_contexts = []
for ii, cx in enumerate(StoragePresentationContexts):
cx.context_id = ii * 2 + 1
cx.SCP = True
cx.SCU = True
self.requestor_contexts.append(cx)
# Acceptor presentation contexts - no max
self.acceptor_contexts = []
for uid in UID_dictionary:
context = PresentationContext()
context.context_id = 1
context.abstract_syntax = uid
context.transfer_syntax = ['1.2.840.10008.1.2']
context.Result = 0x00
context.SCP = True
context.SCU = True
self.acceptor_contexts.append(context)
def time_ps_rq_role(self):
"""Time a presentation service with SCP/SCU role negotiation."""
for ii in range(100):
negotiate_as_requestor(
self.requestor_contexts,
self.acceptor_contexts
)
class TimePresentationAcceptor(object):
"""Time presentation context negotiation as acceptor"""
def setup(self):
# Requestor presentation contexts - max 128
self.requestor_contexts = []
for ii, cx in enumerate(StoragePresentationContexts):
cx.context_id = ii * 2 + 1
self.requestor_contexts.append(cx)
# Acceptor presentation contexts - no max
self.acceptor_contexts = []
for uid in UID_dictionary:
cx = PresentationContext()
cx.abstract_syntax = uid
cx.transfer_syntax = ['1.2.840.10008.1.2',
'1.2.840.10008.1.2.1',
'1.2.840.10008.1.2.2']
self.acceptor_contexts.append(cx)
def time_ps_ac_basic(self):
"""Time a basic presentation service negotiation"""
for ii in range(100):
negotiate_as_acceptor(
self.requestor_contexts,
self.acceptor_contexts
)
class TimePresentationRequestor(object):
"""Time presentation context negotiation as requestor"""
def setup(self):
# Requestor presentation contexts - max 126
self.requestor_contexts = []
for ii, cx in enumerate(StoragePresentationContexts):
cx.context_id = ii * 2 + 1
self.requestor_contexts.append(cx)
# Acceptor presentation contexts - no max
self.acceptor_contexts = []
for ii, cx in enumerate(StoragePresentationContexts):
cx = deepcopy(cx)
cx.context_id = ii * 2 + 1
cx.transfer_syntax = ['1.2.840.10008.1.2']
cx.result = 0x00
self.acceptor_contexts.append(cx)
def time_ps_rq_basic(self):
"""Time a basic presentation service negotiation."""
for ii in range(100):
negotiate_as_requestor(
self.requestor_contexts,
self.acceptor_contexts
)