2011-09-11 08:35:18 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import sys
|
2011-11-23 12:33:58 +01:00
|
|
|
import os, mapnik
|
2011-09-11 08:35:18 +02:00
|
|
|
from timeit import Timer, time
|
|
|
|
from nose.tools import *
|
2013-06-03 04:28:24 +02:00
|
|
|
from utilities import execution_path, run_all
|
2011-09-11 08:35:18 +02:00
|
|
|
|
|
|
|
def setup():
|
|
|
|
# All of the paths used are relative, if we run the tests
|
|
|
|
# from another directory we need to chdir()
|
|
|
|
os.chdir(execution_path('.'))
|
|
|
|
|
|
|
|
combinations = ['png',
|
|
|
|
'png8',
|
|
|
|
'png8:m=o',
|
|
|
|
'png8:m=h',
|
|
|
|
'png8:m=o:t=0',
|
|
|
|
'png8:m=o:t=1',
|
2012-10-25 22:15:33 +02:00
|
|
|
'png8:m=o:t=2',
|
2011-09-11 08:35:18 +02:00
|
|
|
'png8:m=h:t=0',
|
|
|
|
'png8:m=h:t=1',
|
2012-10-25 22:15:33 +02:00
|
|
|
'png8:m=h:t=2',
|
2011-09-11 08:35:18 +02:00
|
|
|
'png:z=1',
|
2012-12-04 00:28:12 +01:00
|
|
|
'png:z=1:t=0', # forces rbg, no a
|
2011-09-11 08:35:18 +02:00
|
|
|
'png8:z=1',
|
|
|
|
'png8:z=1:m=o',
|
|
|
|
'png8:z=1:m=h',
|
|
|
|
'png8:z=1:c=1',
|
2012-10-25 22:15:33 +02:00
|
|
|
'png8:z=1:c=24',
|
|
|
|
'png8:z=1:c=64',
|
|
|
|
'png8:z=1:c=128',
|
|
|
|
'png8:z=1:c=200',
|
|
|
|
'png8:z=1:c=255',
|
|
|
|
'png8:z=9:c=64',
|
|
|
|
'png8:z=9:c=128',
|
|
|
|
'png8:z=9:c=200',
|
2011-09-11 08:35:18 +02:00
|
|
|
'png8:z=1:c=50:m=h',
|
|
|
|
'png8:z=1:c=1:m=o',
|
|
|
|
'png8:z=1:c=1:m=o:s=filtered',
|
|
|
|
'png:z=1:s=filtered',
|
|
|
|
'png:z=1:s=huff',
|
|
|
|
'png:z=1:s=rle',
|
2015-02-02 23:27:18 +01:00
|
|
|
'png8:m=h:g=2.0',
|
|
|
|
'png8:m=h:g=1.0',
|
2014-06-12 07:43:36 +02:00
|
|
|
'png:e=miniz',
|
|
|
|
'png8:e=miniz'
|
2011-09-11 08:35:18 +02:00
|
|
|
]
|
|
|
|
|
2012-11-09 01:13:51 +01:00
|
|
|
tiles = [
|
|
|
|
'blank',
|
|
|
|
'solid',
|
|
|
|
'many_colors',
|
|
|
|
'aerial_24'
|
|
|
|
]
|
|
|
|
|
|
|
|
iterations = 10
|
|
|
|
|
2011-09-11 08:35:18 +02:00
|
|
|
def do_encoding():
|
|
|
|
|
|
|
|
image = None
|
2012-02-24 22:13:56 +01:00
|
|
|
|
2011-09-11 08:35:18 +02:00
|
|
|
results = {}
|
|
|
|
sortable = {}
|
2012-02-24 22:13:56 +01:00
|
|
|
|
2011-09-11 08:35:18 +02:00
|
|
|
def run(func, im, format, t):
|
|
|
|
global image
|
|
|
|
image = im
|
|
|
|
start = time.time()
|
|
|
|
set = t.repeat(iterations,1)
|
|
|
|
elapsed = (time.time() - start)
|
|
|
|
min_ = min(set)*1000
|
|
|
|
avg = (sum(set)/len(set))*1000
|
|
|
|
name = func.__name__ + ' ' + format
|
2012-11-08 22:42:18 +01:00
|
|
|
results[name] = [min_,avg,elapsed*1000,name,len(func())]
|
2012-10-25 22:15:33 +02:00
|
|
|
sortable[name] = [min_]
|
2011-09-11 08:35:18 +02:00
|
|
|
|
2012-11-09 01:13:51 +01:00
|
|
|
if 'blank' in tiles:
|
|
|
|
def blank():
|
|
|
|
return eval('image.tostring("%s")' % c)
|
|
|
|
blank_im = mapnik.Image(512,512)
|
|
|
|
for c in combinations:
|
|
|
|
t = Timer(blank)
|
|
|
|
run(blank,blank_im,c,t)
|
|
|
|
|
|
|
|
if 'solid' in tiles:
|
|
|
|
def solid():
|
|
|
|
return eval('image.tostring("%s")' % c)
|
|
|
|
solid_im = mapnik.Image(512,512)
|
|
|
|
solid_im.background = mapnik.Color("#f2efe9")
|
|
|
|
for c in combinations:
|
|
|
|
t = Timer(solid)
|
|
|
|
run(solid,solid_im,c,t)
|
|
|
|
|
|
|
|
if 'many_colors' in tiles:
|
|
|
|
def many_colors():
|
|
|
|
return eval('image.tostring("%s")' % c)
|
|
|
|
# lots of colors: http://tile.osm.org/13/4194/2747.png
|
|
|
|
many_colors_im = mapnik.Image.open('../data/images/13_4194_2747.png')
|
|
|
|
for c in combinations:
|
|
|
|
t = Timer(many_colors)
|
|
|
|
run(many_colors,many_colors_im,c,t)
|
|
|
|
|
|
|
|
if 'aerial_24' in tiles:
|
|
|
|
def aerial_24():
|
|
|
|
return eval('image.tostring("%s")' % c)
|
|
|
|
aerial_24_im = mapnik.Image.open('../data/images/12_654_1580.png')
|
|
|
|
for c in combinations:
|
|
|
|
t = Timer(aerial_24)
|
|
|
|
run(aerial_24,aerial_24_im,c,t)
|
2012-10-25 22:15:33 +02:00
|
|
|
|
2011-09-11 08:35:18 +02:00
|
|
|
for key, value in sorted(sortable.iteritems(), key=lambda (k,v): (v,k)):
|
|
|
|
s = results[key]
|
2012-11-08 22:42:18 +01:00
|
|
|
min_ = str(s[0])[:6]
|
|
|
|
avg = str(s[1])[:6]
|
2011-09-11 08:35:18 +02:00
|
|
|
elapsed = str(s[2])[:6]
|
2012-10-25 22:15:33 +02:00
|
|
|
percent_reduction = s[4]
|
2011-09-11 08:35:18 +02:00
|
|
|
name = s[3]
|
2012-10-25 22:15:33 +02:00
|
|
|
size = s[4]
|
2012-11-08 22:42:18 +01:00
|
|
|
print 'min: %sms | avg: %sms | total: %sms | len: %s <-- %s' % (min_,avg,elapsed,size,name)
|
2012-02-24 22:13:56 +01:00
|
|
|
|
2011-09-11 08:35:18 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
setup()
|
|
|
|
do_encoding()
|
2014-07-14 18:34:20 +02:00
|
|
|
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
|