MCPcopy Index your code
hub / github.com/bslatkin/effectivepython / heap_overdue_benchmark

Function heap_overdue_benchmark

example_code/item_104.py:274–291  ·  view source on GitHub ↗
(count)

Source from the content-addressed store, hash-verified

272
273print("Example 19")
274def heap_overdue_benchmark(count):
275 def prepare():
276 to_add = list(range(count))
277 random.shuffle(to_add)
278 return [], to_add
279
280 def run(queue, to_add):
281 for i in to_add:
282 heappush(queue, i)
283 while queue:
284 heappop(queue)
285
286 return timeit.timeit(
287 setup="queue, to_add = prepare()",
288 stmt=f"run(queue, to_add)",
289 globals=locals(),
290 number=1,
291 )
292
293
294print("Example 20")

Callers 1

item_104.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected