[Tutor] how to calculate execution time and complexity
Praveen Singh
c2praveen30jun at gmail.com
Fri Oct 28 08:31:23 CEST 2011
.
> Thanks Christian for your links and code!!!!
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
>
> To unsubscribe or change subscription options:http://mail.python.org/mailman/listinfo/tutor
>
>
> Below [1] is how I would write it, which is simply a re-factoring of your
> code so it's cleaner and more compact. For calculating execution time you
> can use the `timeit` module [2] and for more in-depth analysis you can look
> at `profile` [3] and further to the bare-bones `dis` [4].
>
> [1]
> >>> def splitWord(word, number):
> ... x = []
> ... for y in xrange(0, len(word), number):
> ... x.append(word[y:y+number])
> ... return x
> ...
> >>> splitWord('google', 1)
> ['g', 'o', 'o', 'g', 'l', 'e']
>
> >>> splitWord('google', 2)
> ['go', 'og', 'le']
> >>> splitWord('google', 3)
> ['goo', 'gle']
> >>> splitWord('google', 4)
> ['goog', 'le']
> >>> splitWord('google', 5)
> ['googl', 'e']
> >>> splitWord('google', 6)
> ['google']
> >>> splitWord('google', 7)
> ['google']
>
> [2] http://www.doughellmann.com/PyMOTW/timeit/
> [3] http://www.doughellmann.com/PyMOTW/profile/index.html#module-profile
> [4] http://www.doughellmann.com/PyMOTW/dis/
>
> --
>
> Christian Witts
> Python Developer
>
> **
>
--
www.tricksfind.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111028/d4bb7c7f/attachment-0001.html>
More information about the Tutor
mailing list