summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2019-03-25 08:20:53 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2019-03-25 08:20:53 (GMT)
commit68d228f174ceed151200e7e0b44ffc5edd4e0ea2 (patch)
treeb202f156ddd148ddb0bea3976c95b2c3bc05b885 /Tools/scripts
parent5e333784f007950f22de44c1ffab5b0c03d6691f (diff)
downloadcpython-68d228f174ceed151200e7e0b44ffc5edd4e0ea2.zip
cpython-68d228f174ceed151200e7e0b44ffc5edd4e0ea2.tar.gz
cpython-68d228f174ceed151200e7e0b44ffc5edd4e0ea2.tar.bz2
bpo-35884: Add string-keys-only microbenchmark for dict access to var_access_benchmark.py (GH-11905)
Diffstat (limited to 'Tools/scripts')
-rw-r--r--Tools/scripts/var_access_benchmark.py40
1 files changed, 28 insertions, 12 deletions
diff --git a/Tools/scripts/var_access_benchmark.py b/Tools/scripts/var_access_benchmark.py
index 44cb200..03b712d 100644
--- a/Tools/scripts/var_access_benchmark.py
+++ b/Tools/scripts/var_access_benchmark.py
@@ -196,23 +196,31 @@ def read_dict(trials=trials, a={0: 1}):
a[0]; a[0]; a[0]; a[0]; a[0]
a[0]; a[0]; a[0]; a[0]; a[0]
+def read_strdict(trials=trials, a={'key': 1}):
+ for t in trials:
+ a['key']; a['key']; a['key']; a['key']; a['key']
+ a['key']; a['key']; a['key']; a['key']; a['key']
+ a['key']; a['key']; a['key']; a['key']; a['key']
+ a['key']; a['key']; a['key']; a['key']; a['key']
+ a['key']; a['key']; a['key']; a['key']; a['key']
+
def list_append_pop(trials=trials, a=[1]):
ap, pop = a.append, a.pop
for t in trials:
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
def deque_append_pop(trials=trials, a=deque([1])):
ap, pop = a.append, a.pop
for t in trials:
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
- ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop();
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
+ ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop(); ap(1); pop()
def deque_append_popleft(trials=trials, a=deque([1])):
ap, pop = a.append, a.popleft
@@ -247,6 +255,14 @@ def write_dict(trials=trials, a={0: 1}):
a[0]=1; a[0]=1; a[0]=1; a[0]=1; a[0]=1
a[0]=1; a[0]=1; a[0]=1; a[0]=1; a[0]=1
+def write_strdict(trials=trials, a={'key': 1}):
+ for t in trials:
+ a['key']=1; a['key']=1; a['key']=1; a['key']=1; a['key']=1
+ a['key']=1; a['key']=1; a['key']=1; a['key']=1; a['key']=1
+ a['key']=1; a['key']=1; a['key']=1; a['key']=1; a['key']=1
+ a['key']=1; a['key']=1; a['key']=1; a['key']=1; a['key']=1
+ a['key']=1; a['key']=1; a['key']=1; a['key']=1; a['key']=1
+
def loop_overhead(trials=trials):
for t in trials:
pass
@@ -266,9 +282,9 @@ if __name__=='__main__':
write_local, write_nonlocal, write_global,
write_classvar, write_instancevar, write_instancevar_slots,
'\nData structure read access:',
- read_list, read_deque, read_dict,
+ read_list, read_deque, read_dict, read_strdict,
'\nData structure write access:',
- write_list, write_deque, write_dict,
+ write_list, write_deque, write_dict, write_strdict,
'\nStack (or queue) operations:',
list_append_pop, deque_append_pop, deque_append_popleft,
'\nTiming loop overhead:',