Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions sdk/core/azure-core/azure/core/_pipeline_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,22 @@ def _build_pipeline(self, config, **kwargs): # pylint: disable=no-self-use
ContentDecodePolicy(**kwargs)
]
if isinstance(per_call_policies, Iterable):
for policy in per_call_policies:
policies.append(policy)
Comment on lines -126 to -127
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for is the slowest.

speed

import time

# Compare runtime of three methods
list_sizes = [i * 400000 for i in range(30)]
runtimes_1 = []  # Method 1: + Operator
runtimes_2 = []  # Method 2: += Operator
runtimes_3 = []  # Method 3: extend()
runtimes_4 = []  # Method 3: for
for size in list_sizes:
    to_add = list(range(size))

    # Get time stamps
    time_0 = time.time()
    lst = [1]
    lst = lst + to_add
    time_1 = time.time()
    lst = [1]
    lst += to_add
    time_2 = time.time()
    lst = [1]
    lst.extend(to_add)
    time_3 = time.time()
    lst = [1]
    for i in to_add:
        lst.append(i)
    time_4 = time.time()
    # Calculate runtimes
    runtimes_1.append((size, time_1 - time_0))
    runtimes_2.append((size, time_2 - time_1))
    runtimes_3.append((size, time_3 - time_2))
    runtimes_4.append((size, time_4 - time_3))
# Plot everything
import matplotlib.pyplot as plt
import numpy as np

runtimes_1 = np.array(runtimes_1)
runtimes_2 = np.array(runtimes_2)
runtimes_3 = np.array(runtimes_3)
runtimes_4 = np.array(runtimes_4)
print(runtimes_1)
print(runtimes_2)
print(runtimes_3)
print(runtimes_4)
plt.plot(runtimes_1[:, 0], runtimes_1[:, 1], label='Method 1: +')
plt.plot(runtimes_2[:, 0], runtimes_2[:, 1], label='Method 2: +=')
plt.plot(runtimes_3[:, 0], runtimes_3[:, 1], label='Method 3: extend()')
plt.plot(runtimes_4[:, 0], runtimes_4[:, 1], label='Method 4: for')
plt.xlabel('list size')
plt.ylabel('runtime (seconds)')
plt.legend()
plt.savefig('speed.png', dpi=400)
plt.show()

Code snippet from https://blog.finxter.com/python-list-concatenation-add-vs-inplace-add-vs-extend/

policies.extend(per_call_policies)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(For your another PR), do we need list(per_call_policies) here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. list.extend(iterable) by definition takes any iterable.

else:
policies.append(per_call_policies)

policies = policies + [config.redirect_policy,
config.retry_policy,
config.authentication_policy,
config.custom_hook_policy]
policies.extend([config.redirect_policy,
config.retry_policy,
config.authentication_policy,
config.custom_hook_policy])
if isinstance(per_retry_policies, Iterable):
for policy in per_retry_policies:
policies.append(policy)
policies.extend(per_retry_policies)
else:
policies.append(per_retry_policies)

policies = policies + [config.logging_policy,
DistributedTracingPolicy(**kwargs),
config.http_logging_policy or HttpLoggingPolicy(**kwargs)]
policies.extend([config.logging_policy,
DistributedTracingPolicy(**kwargs),
config.http_logging_policy or HttpLoggingPolicy(**kwargs)])

if not transport:
transport = RequestsTransport(**kwargs)
Expand Down