File: time_parsing.py

package info (click to toggle)
zim 0.76.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,952 kB
  • sloc: python: 68,612; xml: 1,270; javascript: 512; sh: 101; makefile: 47
file content (71 lines) | stat: -rwxr-xr-x 1,602 bytes parent folder | download | duplicates (4)
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
67
68
69
70
71
#!/usr/bin/python3


# Copyright 2012 Jaap Karssenberg <jaap.karssenberg@gmail.com>

import sys
sys.path.insert(0, '.')

import zim.formats
import zim.fs
import tests

def setup():
	global parser, dumper
	parser = zim.formats.get_parser('wiki')
	dumper = zim.formats.get_dumper('wiki')

	global wikitext, parsetree
	wikitext = zim.fs.File('tests/data/formats/wiki.txt').read()
	xml = zim.fs.File('tests/data/formats/parsetree.xml').read().rstrip('\n')
	parsetree = tests.new_parsetree_from_xml(xml)

	global smalltext, smalltree
	smalltext = "foo **bar** baz\n"
	xml = "<?xml version='1.0' encoding='utf-8'?><zim-tree>foo <strong>bar</strong> baz\n</zim-tree>"
	smalltree = tests.new_parsetree_from_xml(xml)

def timeParsing():
	parser.parse(wikitext)


def timeDumping():
	dumper.dump(parsetree)


def timeParsingSmall():
	parser.parse(smalltext)


def timeDumpingSmall():
	dumper.dump(smalltree)


if __name__ == '__main__':
	from timeit import Timer
	reps = 5
	passes = 1000
	funcs = sorted([n for n in dir() if n.startswith('time')])

	print("Rep: %i, Passes: %i" % (reps, passes))
	print("Plan: %s" % ', '.join(funcs))
	print('')
	print("Func\tMin\tMax\tAvg [msec/pass]")

	for func in funcs:
		setupcode = "from __main__ import setup, %s; setup()" % func
		testcode = "%s()" % func

		t = Timer(testcode, setupcode)
		try:
			result = t.repeat(reps, passes)
		except:
			print("FAILED running %s" % func)
			t.print_exc()
		else:
			print("%s\t%.2f\t%.2f\t%.2f" % (
				func,
				(1E+3 * min(result) / passes),
				(1E+3 * max(result) / passes),
				(1E+3 * sum(result) / (reps * passes)),
			))