/usr/bin/mapnik-speed-check is in mapnik-utils 2.2.0+ds1-6build2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #! /usr/bin/python
import sys
import mapnik
#import mapnik
from timeit import Timer, time
if not len(sys.argv) >= 3:
sys.exit('usage: mapnik-speed-check <stylesheet> <iterations> [minx,miny,maxx,maxy]')
m = mapnik.Map(256,256)
stylesheet = sys.argv[1]
TOTAL_TIME = 0
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():
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):
min_ = str(min(set)*1000)[:6]
avg = str((sum(set)/len(set))*1000)[:6]
print 'min: %sms | avg: %sms | total: %ss' % (min_,avg,str(TOTAL_TIME)[:6])
if __name__=='__main__':
# if passed, set up bbox
#test_ = "load()"
test_ = "render()"
init(stylesheet)
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)
# load once - making sure mmap'd shapefiles are loaded
eval(test_)
TOTAL_TIME = 0
# now actually run the test
t = Timer(test_, "from __main__ import %s" % test_.replace('()',''))
iterations = int(sys.argv[2])
f_(t.repeat(iterations,1))
|