dict
call - write as literal 55 setup_kwargs = dict(zip_safe=0)
56else:
57 from distutils.core import setup
58 setup_kwargs = dict() 59
60
61storage_dirs = [ ('storage/ceres/dummy.txt', []), ('storage/whisper/dummy.txt',[]),
list
call - write as literal175
176 # No bucket of this size exists, create it
177 while nr_points > len(self.buckets):
178 self.buckets.append(list())179
180 # Remove existing metrics from its bucket
181 if nr_points > 1:
list
call - write as literal155 pop().
156 """
157 def __init__(self, cache):
158 self.buckets = list()159 super(BucketMaxStrategy, self).__init__(cache)
160
161 def choose_item(self):
dict
call - write as literal 19 elif size > 0:
20 return LRUCache(size)
21 else:
22 return dict() 23
24
25class RuleManager(object):
Using the literal syntax can give minor performance bumps compared to using function calls to create dict
, list
and tuple
.
In [1]: timeit.timeit(stmt="dict()", number=100000000)
Out[1]: 9.560388602000103
In [2]: timeit.timeit(stmt="{}", number=100000000)
Out[2]: 1.685333584000091
In [3]: timeit.timeit(stmt="tuple()", number=100000000)
Out[3]: 4.509182139000131
In [4]: timeit.timeit(stmt="()", number=100000000)
Out[4]: 0.5455615430000762
In [5]: timeit.timeit(stmt="list()", number=100000000)
Out[5]: 7.356000728000254
In [6]: timeit.timeit(stmt="[]", number=100000000)
Out[6]: 1.573771306999788
This is because here, the name dict
must be looked up in the global scope in case it has been rebound.
Same goes for the other two types list()
and tuple()
.