2010-11-24 03:03:09 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys
|
2012-02-02 01:44:50 +01:00
|
|
|
import mapnik
|
2010-11-24 03:03:09 +01:00
|
|
|
#import mapnik
|
|
|
|
from timeit import Timer, time
|
|
|
|
|
|
|
|
if not len(sys.argv) >= 3:
|
2011-09-10 20:27:31 +02:00
|
|
|
sys.exit('usage: mapnik-speed-check <stylesheet> <iterations> [minx,miny,maxx,maxy]')
|
2010-11-24 03:03:09 +01:00
|
|
|
|
|
|
|
m = mapnik.Map(256,256)
|
2011-10-29 00:13:52 +02:00
|
|
|
stylesheet = sys.argv[1]
|
2010-11-24 03:03:09 +01:00
|
|
|
|
|
|
|
TOTAL_TIME = 0
|
|
|
|
|
2011-10-29 00:13:52 +02:00
|
|
|
def load():
|
|
|
|
global TOTAL_TIME
|
|
|
|
global stylesheet
|
|
|
|
start = time.time()
|
|
|
|
m = mapnik.Map(256,256)
|
|
|
|
mapnik.load_map(m,stylesheet)
|
|
|
|
TOTAL_TIME += (time.time() - start)
|
|
|
|
|
|
|
|
def init(stylesheet):
|
|
|
|
mapnik.load_map(m,stylesheet)
|
|
|
|
m.zoom_all()
|
|
|
|
|
|
|
|
def render():
|
2010-11-24 03:03:09 +01:00
|
|
|
global TOTAL_TIME
|
|
|
|
start = time.time()
|
|
|
|
im = mapnik.Image(m.width,m.height)
|
|
|
|
mapnik.render(m,im)
|
|
|
|
TOTAL_TIME += (time.time() - start)
|
|
|
|
|
|
|
|
def f_(set):
|
2011-09-10 20:22:57 +02:00
|
|
|
min_ = str(min(set)*1000)[:6]
|
|
|
|
avg = str((sum(set)/len(set))*1000)[:6]
|
2011-09-10 01:47:27 +02:00
|
|
|
print 'min: %sms | avg: %sms | total: %ss' % (min_,avg,str(TOTAL_TIME)[:6])
|
2010-11-24 03:03:09 +01:00
|
|
|
|
|
|
|
if __name__=='__main__':
|
|
|
|
# if passed, set up bbox
|
2012-03-09 21:04:37 +01:00
|
|
|
|
|
|
|
#test_ = "load()"
|
|
|
|
test_ = "render()"
|
|
|
|
init(stylesheet)
|
|
|
|
|
2010-11-24 03:03:09 +01:00
|
|
|
if len(sys.argv) == 4:
|
|
|
|
bbox = sys.argv[3]
|
|
|
|
if ',' in bbox:
|
|
|
|
parts = bbox.split(',')
|
|
|
|
else:
|
|
|
|
parts = bbox.split(' ')
|
|
|
|
env = mapnik.Box2d(*map(float,parts))
|
|
|
|
m.zoom_to_box(env)
|
2011-10-29 00:13:52 +02:00
|
|
|
|
2010-11-24 03:03:09 +01:00
|
|
|
# load once - making sure mmap'd shapefiles are loaded
|
|
|
|
eval(test_)
|
2010-12-16 17:32:06 +01:00
|
|
|
TOTAL_TIME = 0
|
|
|
|
|
|
|
|
# now actually run the test
|
2011-10-29 00:13:52 +02:00
|
|
|
t = Timer(test_, "from __main__ import %s" % test_.replace('()',''))
|
2010-12-16 17:32:06 +01:00
|
|
|
iterations = int(sys.argv[2])
|
|
|
|
f_(t.repeat(iterations,1))
|