Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102392
| From | "Sven R. Kunze" <srkunze@mail.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Heap Implementation |
| Date | 2016-02-01 20:32 +0100 |
| Message-ID | <mailman.6.1454355132.3032.python-list@python.org> (permalink) |
| References | <mailman.148.1454194055.2338.python-list@python.org> <56ad6800$0$14486$c3e8da3@news.astraweb.com> |
On 31.01.2016 02:48, Steven D'Aprano wrote:
> On Sunday 31 January 2016 09:47, Sven R. Kunze wrote:
>
>> @all
>> What's the best/standardized tool in Python to perform benchmarking?
> timeit
Thanks, Steven.
Maybe, I am doing it wrong but I get some weird results:
>>> min(timeit.Timer('for _ in range(10000): heappop(h)', 'from heapq
import heappop; h=list(range(10000000))').repeat(10, 1)),
min(timeit.Timer('for _ in range(10000): h.pop()', 'from xheap import
Heap; h=Heap(range(10000000))').repeat(10, 1))
(0.017267618000005314, 0.01615345600021101)
>>> min(timeit.Timer('for _ in range(100000): heappop(h)', 'from heapq
import heappop; h=list(range(10000000))').repeat(10, 1)),
min(timeit.Timer('for _ in range(100000): h.pop()', 'from xheap import
Heap; h=Heap(range(10000000))').repeat(10, 1))
(0.12321608699949138, 0.13042051299999002)
>>> min(timeit.Timer('for _ in range(10000): heappop(h)', 'from heapq
import heappop; h=list(range(1000000))').repeat(10, 1)),
min(timeit.Timer('for _ in range(10000): h.pop()', 'from xheap import
Heap; h=Heap(range(1000000))').repeat(10, 1))
(0.010081621999233903, 0.008791901999757101)
>>> min(timeit.Timer('for _ in range(1000000): heappop(h)', 'from heapq
import heappop; h=list(range(10000000))').repeat(10, 1)),
min(timeit.Timer('for _ in range(1000000): h.pop()', 'from xheap import
Heap; h=Heap(range(10000000))').repeat(10, 1))
(0.6218949679996513, 0.7172151949998806)
How can it be that my wrapper is sometimes faster and sometimes slower
than heapq? I wouldn't mind slower, but faster*?
Best,
Sven
* that behavior is reproducible also for other combos and other machines.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Heap Implementation "Sven R. Kunze" <srkunze@mail.de> - 2016-01-30 23:47 +0100
Re: Heap Implementation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-01-31 12:48 +1100
Re: Heap Implementation "Sven R. Kunze" <srkunze@mail.de> - 2016-02-01 20:32 +0100
Re: Heap Implementation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-02-02 16:38 +1100
Re: Heap Implementation Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-02-02 14:53 +0000
csiph-web