Hi Ethan, On Fri, Jun 12, 2009 at 11:33 PM, evlu...@gmail.com<evlu...@gmail.com> wrote: > > I'm working on some code that is very computationally intensive. I'm > pretty sure my algorithm is good, but I know that tiny differences in > wording in sage can make a huge runtime difference. Is there any site/ > blog/whatever that I could look at to find out what makes for fast > sage code? I figure this is preferable to constantly spamming sage- > support with optimization questions.
If you don't mind learning Cython, you can investigate how to use Cython for your application. See www.cython.org The following paper discusses how to use Cython to speed up numerical computations: http://simula.no/research/scientific/publications/Simula.SC.578 If you're looking for tips on speeding up your Python code, the Python wiki has this page http://wiki.python.org/moin/PythonSpeed/PerformanceTips However, one should avoid premature optimization. That is, first identify those parts of your code that are taking up the most time. The following tutorial talks about profiling and optimizing Python code: http://www.onlamp.com/pub/a/python/2005/12/15/profiling.html?CMP=OTC-6YE827253101&ATT=Profiling+and+Optimizing+Python When writing for loops, I tend to avoid range as much as I can. I usually use xrange, instead of range. That's because xrange returns a generator object, as opposed to range which returns a list. A generator object returned by xrange generates the list elements on demand, so for looping purposes, xrange is usually much more memory efficient than range. You can find documentation for xrange at http://docs.python.org/library/functions.html?highlight=xrange#xrange You might also want to consider the yield statement, which is documented at http://docs.python.org/reference/simple_stmts.html#the-yield-statement Here's a tutorial that explains how to use yield in the context of computing permutations: http://ttsiodras.googlepages.com/yield.html Hope that helps. -- Regards Minh Van Nguyen --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---