diff --git a/chunk.py b/chunk.py index 13a387b..7a5fc15 100644 --- a/chunk.py +++ b/chunk.py @@ -924,7 +924,8 @@ class ChunkRenderer(object): # check to see if there are any signs in the persistentData list that are from this chunk. # if so, remove them from the persistentData list (since they're have been added to the world.POI # list above. - self.queue.put(['removePOI', (self.chunkX, self.chunkY)]) + if self.queue: + self.queue.put(['removePOI', (self.chunkX, self.chunkY)]) return img diff --git a/contrib/benchmark.py b/contrib/benchmark.py new file mode 100644 index 0000000..145654e --- /dev/null +++ b/contrib/benchmark.py @@ -0,0 +1,51 @@ +import chunk +import world +import tempfile +import glob +import time +import cProfile +import os +import sys +import shutil + +# Simple Benchmarking script. Usage and example: + +# $ python contrib/benchmark.py World4/ +# Rendering 50 chunks... +# Took 20.290062 seconds or 0.405801 seconds per chunk, or 2.464261 chunks per second + + +# create a new, empty, cache dir +cachedir = tempfile.mkdtemp(prefix="benchmark_cache", dir=".") +if os.path.exists("benchmark.prof"): os.unlink("benchmark.prof") + +w = world.WorldRenderer("World4", cachedir) + +numchunks = 50 +chunklist = w._find_chunkfiles()[:numchunks] + +print "Rendering %d chunks..." % (numchunks) +def go(): + for f in chunklist: + chunk.render_and_save(f[2], w.cachedir, w, (None,None), None) +start = time.time() +if "-profile" in sys.argv: + cProfile.run("go()", 'benchmark.prof') +else: + go() +stop = time.time() + +delta = stop - start + +print "Took %f seconds or %f seconds per chunk, or %f chunks per second" % (delta, delta/numchunks, numchunks/delta) + +if "-profile" in sys.argv: + print "Profile is below:\n----\n" + + import pstats + p = pstats.Stats('benchmark.prof') + + p.strip_dirs().sort_stats("cumulative").print_stats(20) + + +shutil.rmtree(cachedir)