source: src/gheat/__/bin/speed-test.py@ 14201

Last change on this file since 14201 was 8853, checked in by dennisw, 14 years ago

stageplan_0.1 - toegevoegd
gheat - sourcecode toegevoegd
website_ontwerp - map aangepast, komt nu beter overeen met idee dat ik heb

File size: 1.5 KB
Line 
1#!/usr/bin/env python
2"""Set up and run a profiling scenario for gheat.
3
4Usage:
5
6 speed-test.py <backend> [<iterations>]
7
8The output will be a cProfile report. <iterations> defaults to 1. The expensive
9part is tile rebuilding, so we isolate that here.
10
11"""
12import cProfile
13import os
14import pstats
15import sys
16
17import aspen; aspen.configure()
18import gheat
19
20
21# Parse and validate command line arguments.
22# ==========================================
23
24USAGE = "Usage: speed-test.py <backend> [<iterations>]"
25
26if len(sys.argv) < 2:
27 print >> sys.stderr, USAGE
28 raise SystemExit
29image_library = sys.argv[1].lower()
30assert image_library in ('pygame', 'pil'), "bad image library"
31if image_library == 'pygame':
32 from gheat import pygame_ as backend
33elif image_library == 'pil':
34 from gheat import pil_ as backend
35
36try:
37 iterations = int(sys.argv[2])
38except IndexError:
39 iterations = 1
40
41
42# Set up the test.
43# ================
44# This depends on our default data set for a juicy tile.
45
46color_path = os.path.join(aspen.paths.__, 'etc', 'color-schemes', 'classic.png')
47color_scheme = backend.ColorScheme('classic', color_path)
48dots = gheat.load_dots(backend)
49tile = backend.Tile(color_scheme, dots, 4, 4, 6, 'foo.png')
50
51def test():
52 for i in range(iterations):
53 tile.rebuild()
54
55
56# Run it.
57# =======
58
59cProfile.run('test()', 'stats.txt')
60p = pstats.Stats('stats.txt')
61p.strip_dirs().sort_stats('time').print_stats()
62os.remove('stats.txt')
63
Note: See TracBrowser for help on using the repository browser.