Skip to content

Latest commit

 

History

History
42 lines (35 loc) · 2.75 KB

File metadata and controls

42 lines (35 loc) · 2.75 KB

IMPORTANT: The rows Method 2: setdefault, iteritems() in Table 1 and Method 2: setdefault in Table 2 were obtained actually with dict.get() instead of dict.setdefault(). As stated on the 2018-09-16 update, I thought the --use_setdefault option was implemented when I ran the main script compute_avg_run_time.py which was not the case. dict.get() was used instead of dict.setdefault(). Check the newest results where I re-ran the python commands with the updated code.

The following two tables present average run times that were obtained with python scripts having commit HASH c834169f4b7f74f21e3fe3006483baa44f83ef91.


Table 1 Average running times of different methods
of reversing a dict in Python 2.7
Py2 Method Avg time (µsec), 1k items, 100k times Avg time (µsec), 10k items, 1k times Avg time (µsec), 100k items, 1k times
Method 1: dict comprehension, iteritems()

233.02

3009.04

45815.60

Method 1: dict comprehension, items() 273.22 4484.39 73327.81
Method 2: dict.get, iteritems() 772.42 10035.83 125039.90
Method 2: setdefault, iteritems() 910.63 11369.59 131220.12
Method 3: map(reversed, iterable), iteritems() 856.57 10712.58 121904.58


Table 2 Average running times of different methods
of reversing a dict in Python 3
Py3 Method Avg time (µsec), 1k items, 100k times Avg time (µsec), 10k items, 1k times Avg time (µsec), 100k items, 1k times
Method 1: dict comprehension

96.81

946.01

20405.42

Method 2: dict.get 373.60 4287.52 63150.73
Method 2: setdefault 372.67 4321.50 63432.81
Method 3: map(reversed,) 312.13 3190.19 45776.68