Friday, September 14, 2018

kids these days think data structures grow on trees

Args and kwargs are great features of Python.  There is a measurable (though highly variable) cost of them however:

>>> timeit.timeit(lambda: (lambda a, b: None)(1, b=2))
0.16460260000000204

>>> timeit.timeit(lambda: (lambda *a, **kw: None)(1, b=2))
0.21245309999999762


>>> timeit.timeit(lambda: (lambda *a, **kw: None)(1, b=2)) - timeit.timeit(lambda: (lambda a, b: None)(1, b=2))
0.14699769999992895


Constructing that dict and tuple doesn't happen for free:

>>> timeit.timeit(lambda: ((1,), {'b': 2})) - timeit.timeit(lambda: None)
0.16881599999999253


Specifically, it takes about 1/5,000,000th of a second.

5 comments:

  1. I read this article, it is really informative one. Your way of writing and making things clear is very impressible. Thanking you for such an informative article. Data Structures Learning Online Videos

    ReplyDelete
  2. Trees do grow on trees actually

    ReplyDelete
  3. Connect with professional academic writers via Assignment Help in Ireland to finish your papers without any issue. So, buy Online Assignment Help and complete your homework before the due dates.
    Visit us : Assignment Help Online

    ReplyDelete
  4. HP printers are mostly used by peoples for printing and scanning purpose. Sometimes when you send a print command to printer you may get Printer in Error State message on the screen. The error may occur due to various reasons. Contact experts immediately get rid of this error message.

    ReplyDelete
  5. Such a very useful article. Very interesting to read this article. I would like to thank you for the efforts you had made for writing this awesome article.
    Data Science Course in Pune
    Data Science Training in Pune

    ReplyDelete