Re: Using namedtuple instead of pure tuples

2014-03-26 Thread Adam Kaliński
Hi, I improved my benchmarks: http://nbviewer.ipython.org/gist/adamkal/9171081 Alex was right about those variables and new benchmarks have proved it. I also created a draft of how it might look like for Options.get_field_by_name (as this returns 4-tuple): https://github.com/adamkal/django/co

Re: Using namedtuple instead of pure tuples

2014-02-24 Thread Adam Kaliński
Good tips. Thanks! I'll improve them and post as soon as they're ready. Moreover I was thinking that it might be nice to just modify Django to use namedtuples and see how will that influence execution. The problem is that it might be difficult to create reliable tests. If you think that there

Re: Using namedtuple instead of pure tuples

2014-02-23 Thread Alex Gaynor
FWIW these benchmaks are not measuring accurately. Creating a tuple of the form "(1, 2, 3)" (notably, where all the members are literal constants) takes NO time actually, since it's an immutable container of all immutable items, the compiler is able to factor the work out. A benchmark, even as idio

Re: Using namedtuple instead of pure tuples

2014-02-23 Thread Russell Keith-Magee
Hi Stratos, Thanks for providing those benchmarks -- that's really helpful. However, It's all well and good to say that "Doing X takes 0.01s" or "X is 50% slower than Y", but that if the time taken to do X is incredibly small to start with, a 50% slowdown doesnt really matter that much. The fact

Re: Using namedtuple instead of pure tuples

2014-02-23 Thread Adam Kaliński
Oh! And as far as I understand they're equally memory consuming import sys from collections import namedtuple T = namedtuple('T', 'a b c d e') assert sys.getsizeof((1,2,3,4,5)) == sys.getsizeof(T(1,2,3,4,5)) W dniu niedziela, 23 lutego 2014 14:12:38 UTC+1 użytkownik Adam Kaliński napisał: > >

Re: Using namedtuple instead of pure tuples

2014-02-23 Thread Adam Kaliński
I did my own tests with similar results: http://nbviewer.ipython.org/gist/adamkal/9171081 looks like creating a namedtuple is also quite time consuming and it's even hard to compare to tuple here. Good thing is that we have backward compatibility that has no overhead on accessing data. W dn

Re: Using namedtuple instead of pure tuples

2014-02-22 Thread Stratos Moros
Completely unscientific microbenchmarks: ([gist](https://gist.github.com/stratoukos/dcde41ee0903dcdd577a)) >>> from timeit import Timer ## creation # tuple >>> Timer('(1, 2, 3, 4, 5)').timeit() 0.02694106101989746 # namedtuple with args >>> Timer('T(1, 2, 3, 4, 5)', se

Re: Using namedtuple instead of pure tuples

2014-02-22 Thread Florian Apolloner
On Saturday, February 22, 2014 5:24:39 PM UTC+1, Adam Kaliński wrote: > > What do you guys think? > Sounds good, you might check if namedtuple has negative performance effects (I doubt it, but who knows). The reason we didn't add it yet is that it just exists since 2.6. cheers, Florian -- Yo

Using namedtuple instead of pure tuples

2014-02-22 Thread Adam Kaliński
Hi, I was thinking that it would be nice if we could use more power of namedtuples. For example get_field_by_name method returns tuple (field_object, model, direct, m2m) which requires user to dig up what each index means. I think this would increase code readability because data.model is mor