Re: Surprising timeit result

2009-10-26 Thread Steven D'Aprano
On Tue, 27 Oct 2009 04:36:12 +, John O'Hagan wrote: > I sometimes use timeit to see if it's better to check if something needs > doing, or to just do it anyway. This result was surprising: > > setup = 'd1 = {"a":0, "b":0}; d2 = {"a":0, "b":1}' > > Timer('d1.update(d2)', setup).timeit() 2.64

Re: Surprising timeit result

2009-10-26 Thread John O'Hagan
On Tue, 27 Oct 2009, Paul Rubin wrote: > "John O'Hagan" writes: > > Timer('d1.update(d2)', setup).timeit() > > 2.6499271392822266 > > > > Timer('if d1 != d2: d1.update(d2)', setup).timeit() > > 1.0235211849212646 > > > > In other words, in this case it's substantially quicker to check for > > some

Re: Surprising timeit result

2009-10-26 Thread Paul Rubin
"John O'Hagan" writes: > Timer('d1.update(d2)', setup).timeit() > 2.6499271392822266 > > Timer('if d1 != d2: d1.update(d2)', setup).timeit() > 1.0235211849212646 > > In other words, in this case it's substantially quicker to check for > something and then proceed, than it is to just proceed! I'm

Surprising timeit result

2009-10-26 Thread John O'Hagan
I sometimes use timeit to see if it's better to check if something needs doing, or to just do it anyway. This result was surprising: setup = 'd1 = {"a":0, "b":0}; d2 = {"a":0, "b":1}' Timer('d1.update(d2)', setup).timeit() 2.6499271392822266 Timer('if d1 != d2: d1.update(d2)', setup).timeit()