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