forked from MapServer/MapServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclonemaps.py
More file actions
66 lines (54 loc) · 1.97 KB
/
clonemaps.py
File metadata and controls
66 lines (54 loc) · 1.97 KB
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
64
65
66
# $Id$
#
# Timing tests of mapfile parsing vs map cloning
import os
import timeit
from shutil import copyfile
from .testing import TESTMAPFILE, mapscript
# ===========================================================================
# Test 1A: New maps from mapfile
#
# reloading the mapfile each time
print("Test 1A: reloading maps from mapfile")
s = """\
m = mapscript.mapObj(TESTMAPFILE)
"""
t = timeit.Timer(stmt=s, setup="from __main__ import mapscript, TESTMAPFILE")
print("%.2f usec/pass" % (1000000 * t.timeit(number=100) / 100))
# ===========================================================================
# Test 1B: Cloning
#
# Cloning instead of reloading
print("Test 1B: cloning maps instead of reloading")
m = mapscript.mapObj(TESTMAPFILE)
s = """\
c = m.clone()
"""
t = timeit.Timer(stmt=s, setup="from __main__ import m")
print("%.2f usec/pass" % (1000000 * t.timeit(number=100) / 100))
# ===========================================================================
# Test 2: Add 20 dups of the POLYGON layer to see how results scale
timing_map = mapscript.mapObj(TESTMAPFILE)
polygon_layer = timing_map.getLayerByName("POLYGON")
# duplicate POLYGON layer 20 times
for i in range(20):
timing_map.insertLayer(polygon_layer)
assert timing_map.numlayers == 24
TIMINGMAPFILE = os.path.join(os.getcwd(), "timing.map")
timing_map.save(TIMINGMAPFILE)
copyfile("../../tests/fonts.txt", os.path.join(os.getcwd(), "fonts.txt"))
copyfile("../../tests/symbols.txt", os.path.join(os.getcwd(), "symbols.txt"))
# Test 2A: reloading mapfile
print("Test 2A: reloading inflated mapfile")
s = """\
m = mapscript.mapObj(TIMINGMAPFILE)
"""
t = timeit.Timer(stmt=s, setup="from __main__ import mapscript, TIMINGMAPFILE")
print("%.2f usec/pass" % (1000000 * t.timeit(number=100) / 100))
print("Test 2B: cloning inflated mapfile")
m = mapscript.mapObj(TIMINGMAPFILE)
s = """\
c = m.clone()
"""
t = timeit.Timer(stmt=s, setup="from __main__ import m")
print("%.2f usec/pass" % (1000000 * t.timeit(number=100) / 100))