MCPcopy Create free account
hub / github.com/grantjenks/python-sortedcontainers / benchmark_del

Function benchmark_del

tests/benchmark_scale.py:243–273  ·  view source on GitHub ↗

Benchmark sorted list delitem method. Start and limit are an inclusive range of magnitudes. The load of the sorted list is the square root of the size. Measurements are made by sampling performance at each "moment" of a sorted list while items are deleted from it. See `init_sorted

(start, limit, times)

Source from the content-addressed store, hash-verified

241
242
243def benchmark_del(start, limit, times):
244 """Benchmark sorted list delitem method.
245
246 Start and limit are an inclusive range of magnitudes.
247
248 The load of the sorted list is the square root of the size.
249
250 Measurements are made by sampling performance at each "moment" of a sorted
251 list while items are deleted from it. See `init_sorted_list` for how
252 "moment" is used.
253
254 """
255 for exponent in xrange(start, limit + 1):
256 timings = []
257 count = 10 ** exponent
258 sl = sc.SortedList(load=int(count ** (1.0 / 3))) # 2)))
259
260 for attempt in xrange(times):
261 subtimings = []
262
263 for moment in xrange(-5, 0):
264 indices = randindices(count)
265 init_sorted_list(sl, count, moment)
266 gc.collect()
267 subtiming = delitem(sl, indices)
268 subtimings.append(subtiming)
269
270 timing = sum(subtimings)
271 timings.append(timing)
272
273 display('del', timings, count)
274
275
276def display(name, times, size, last=['', 0]):

Callers

nothing calls this directly

Calls 5

randindicesFunction · 0.85
displayFunction · 0.85
appendMethod · 0.80
init_sorted_listFunction · 0.70
delitemFunction · 0.70

Tested by

no test coverage detected