Permalink
Browse files

Accidentally committed to master and pushed, updating develop. :-)

  • Loading branch information...
1 parent 8a1d3d2 commit 23b4e1a353ce19e626989c00cdefe00f13e89ed6 @mathuin committed Jan 7, 2012
Showing with 22 additions and 2 deletions.
  1. +3 −0 mcarray.py
  2. +17 −0 memoize.py
  3. +2 −2 testbuilds.sh
View
@@ -8,6 +8,7 @@
from pymclevel.materials import alphaMaterials
from itertools import product
from multiprocessing import Pool
+from memoize import memoize
from random import randint
import logging
logging.basicConfig(level=logging.WARNING)
@@ -45,10 +46,12 @@ def checkSealevel(string):
return sealevel
# helper functions for pymclevel
+@memoize()
def materialNamed(string):
"Returns block ID for block with name given in string."
return [v.ID for v in alphaMaterials.allBlocks if v.name==string][0]
+@memoize()
def names(blockID):
"Returns block name for given block ID."
return alphaMaterials.names[blockID][0]
View
@@ -0,0 +1,17 @@
+# http://askawizard.blogspot.com/2008/09/decorators-python-saga-part-2_28.html
+class memoize(object):
+ def __init__(self, cache = None):
+ self.cache = cache
+ def __call__(self, function):
+ return Memoized(function, self.cache)
+
+class Memoized(object):
+ def __init__(self, function, cache = None):
+ if cache is None: cache = {}
+ self.function = function
+ self.cache = cache
+ def __call__(self, *args):
+ if args not in self.cache:
+ self.cache[args] = self.function(*args)
+ return self.cache[args]
+
View
@@ -23,7 +23,7 @@
: ${MAPPEROPTS:="-z -w $WORLDDIR -o $IMAGE"}
rm -rf $ARRAYDIR $WORLDDIR $IMAGE && \
-python -m cProfile -o $PROFBAFILE ./BuildArrays.py --region $DATASET --processes 1 $BAOPTS && \
-python -m cProfile -o $PROFBWFILE ./BuildWorld.py --region $DATASET --processes 1 $BWOPTS && \
+time python -m cProfile -o $PROFBAFILE ./BuildArrays.py --region $DATASET --processes 1 $BAOPTS && \
+time python -m cProfile -o $PROFBWFILE ./BuildWorld.py --region $DATASET --processes 1 $BWOPTS && \
$MAPPER $MAPPEROPTS && \
display $IMAGE

0 comments on commit 23b4e1a

Please sign in to comment.