from timeit import Timer t1 = Timer(""" reduce(lambda x, y: x*10+y, (1,2,3,4,5,6,7)) """) t2 = Timer(""" "".join([str(i) for i in (1,2,3,4,5,6,7)]) """)
print("Reduce: {0} | List comprehension: {1}").format(t1.timeit(), t2.timeit()) l'output sulla mia macchina con timeit() è: "Reduce: 1.58372807503 | List comprehension: 2.46447396278" usando Python 2.6.6 (Linux), qualcuno sa spiegare il perché di tale differenza? :-) Il 10 febbraio 2011 17:44, Simone Federici <s.feder...@gmail.com> ha scritto: > Quale è la più performante? > > 2011/2/10 Gianluca Bargelli <g.barge...@gmail.com> >> >> Ops, pardon! >> >> t = (1,2,3,4,5,6,7) >> int("".join([str(i) for i in t])) >> >> La solita fretta :-) >> >> Il 10 febbraio 2011 17:32, Marco Beri <marcob...@gmail.com> ha scritto: >> > 2011/2/10 Gianluca Bargelli <g.barge...@gmail.com> >> >> >> >> Ecco la prima cosa che mi è venuta in mente: >> >> >> >> t = (1,2,3,4,5,6,7) >> >> "".join([str(i) for i in t]) >> >> >> >> Pulita, leggibile...semplice! ;-) >> > >> > E sbagliata :-) >> > Ci manca un int(). >> > >> > _______________________________________________ >> > Python mailing list >> > Python@lists.python.it >> > http://lists.python.it/mailman/listinfo/python >> > >> > >> >> >> >> -- >> -Gianluca >> _______________________________________________ >> Python mailing list >> Python@lists.python.it >> http://lists.python.it/mailman/listinfo/python > > > _______________________________________________ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python > > -- -Gianluca _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python