Thursday, January 31, 2008

Favorite Python Optimizations: Slots

If you are using any objects in Python, here is a quick way to knock a couple of seconds off the execution time - add slots. This is maybe the easiest optimization mod ever. It doesn't produce massive gains, but every little bit helps. So for a basic object like

class MyClass:
def __init__(self, var1, var2, var3):
self.myVar1 = var1
self.myVar2 = var2
self.myVar3 = var3


you add one line creating a list of slots like this:

class MyClass:
__slots__ = ['myVar1', 'myVar2', 'myVar3']
def __init__(self, var1, var2, var3):
self.myVar1 = var1
self.myVar2 = var2
self.myVar3 = var3

and you get a bit of a speed up!

Labels:

Wednesday, January 30, 2008

Learning Scheme

Near the top of my list of 'continuing education' goals is learning Scheme. I have two reasons for this - I use GnuCash to manage my finances and I'm displeased with its reports, and I want to write a small graphics application.

There is a significant need in the knitting community for a software application that takes a drawing or photograph and translates it into a scaled and color-reduced chart for knitting a motif into a garment. The best thing I've found is microRevolt's knitPro. Which I love, but isn't fitting my needs any more. I have the terribly clever idea of knitting traditional tattoo motifs into sweaters, super-large-like, but knitPro is too simplistic for this. And since Gimp was written in Scheme, I think Scheme is probably a wise choice for this. Maybe I can make it an extension to Gimp, we'll see.

I've chosen to use, out of the myriad scheme implementations (over 40 listed at the scheme wiki) the MIT/GNU Scheme. Because I trust them. The Gimp developer's pages weren't instantly forthcoming on the version of scheme they use, but since Gimp is a Gnu project, it's reasonable to think they'd use the MIT/GNU Scheme. I hope.

Hopefully early versions of my scheme-y knitting software will be hosted on sourceforge or something similar soon. Or maybe some Quicken-like reports will be added to GnuCash. Either way, I'm optimistic of getting some immediate use from learning Scheme.

Labels: , ,