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. Just stumbled across your blog and was instantly amazed with all the useful information that is on it. Great post, just what i was looking for and i am looking forward to reading your other posts soon!
    python Training institute in Chennai
    python Training institute in Bangalore
    python Training in Pune

    ReplyDelete
  2. led для любых целей можете найти у нас на сайте Ekodio

    ReplyDelete
  3. Learn Digital Academy . is a dedicated Digital Marketing Institute that provides, A comprehensive Digital Marketing learning experience involves Training, Certification, Internships, and Placement in a reputable Digital Marketing firm.

    ReplyDelete
  4. Assignment Prime is one of the most recommended assignment writing services among candidates. We cater the academic requirements and offer assignment helper qualitative services under good prices. We hold the experience of more than 10 years and with such experience we exactly know what your assignment requires.

    ReplyDelete
  5. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks Joel's Pro Tree Service

    ReplyDelete