Skip to content
Newer
Older
100644 82 lines (69 sloc) 2.31 KB
7ead3fc @trentm Original import of markdown2 from my personal repo.
trentm authored Aug 18, 2007
1 #!/usr/bin/env python
2
3 import os
4 import sys
5 import timeit
6 import time
7 from os.path import *
8 from glob import glob
9
10 from util import hotshotit
11
12
13 DEFAULT_REPEAT = 3
14 DEFAULT_CASES_DIR = "test-cases"
15
16 clock = sys.platform == "win32" and time.clock or time.time
17
18
19 def time_markdown_py(cases_dir, repeat=DEFAULT_REPEAT):
20 sys.path.insert(0, join("..", "test"))
21 import markdown
22 del sys.path[0]
23 markdowner = markdown.Markdown()
24 times = []
25 for i in range(repeat):
26 start = clock()
27 for path in glob(join(cases_dir, "*.text")):
28 f = open(path, 'r')
29 content = f.read()
30 f.close()
31 try:
32 markdowner.convert(content)
33 markdowner.reset()
34 except UnicodeError:
35 pass
36 end = clock()
37 times.append(end - start)
38 print "time_markdown_py: best of %d: %.3fs" % (repeat, min(times))
39
40 #@hotshotit
41 def time_markdown2_py(cases_dir, repeat=DEFAULT_REPEAT):
42 sys.path.insert(0, "..")
43 import markdown2
44 del sys.path[0]
45 markdowner = markdown2.Markdown()
46 times = []
47 for i in range(repeat):
48 start = clock()
49 for path in glob(join(cases_dir, "*.text")):
50 f = open(path, 'r')
51 content = f.read()
52 f.close()
53 markdowner.convert(content)
54 end = clock()
55 times.append(end - start)
56 print "time_markdown2_py: best of %d: %.3fs" % (repeat, min(times))
57
58 def time_markdown_pl(cases_dir, repeat=DEFAULT_REPEAT):
59 times = []
60 for i in range(repeat):
61 start = clock()
62 os.system('perl time_markdown_pl.pl "%s"' % cases_dir)
63 end = clock()
64 times.append(end - start)
65 print "time_markdown_pl: best of %d: %.3fs" % (repeat, min(times))
66
67 def time_all(cases_dir, repeat=DEFAULT_REPEAT):
68 time_markdown_pl(cases_dir, repeat=repeat)
69 time_markdown_py(cases_dir, repeat=repeat)
70 time_markdown2_py(cases_dir, repeat=repeat)
71
72 if __name__ == "__main__":
73 # Usage: $0 [all|markdown.py|markdown2.py|Markdown.pl]
74 selector = len(sys.argv) > 1 and sys.argv[1] or "all"
75 timer_name = "time_%s" % selector.lower().replace('.', '_')
76 d = sys.modules[__name__].__dict__
77 if timer_name not in d:
78 raise ValueError("no '%s' timer function" % timer_name)
79 timer = d[timer_name]
80 timer(DEFAULT_CASES_DIR)
81
Something went wrong with that request. Please try again.