|
Last change
on this file since 1538 was 2, checked in by Yuri Dario, 15 years ago |
|
Initial import for vendor code.
|
-
Property svn:eol-style
set to
native
|
|
File size:
514 bytes
|
| Line | |
|---|
| 1 | import re
|
|---|
| 2 | import time
|
|---|
| 3 |
|
|---|
| 4 | def main():
|
|---|
| 5 | s = "\13hello\14 \13world\14 " * 1000
|
|---|
| 6 | p = re.compile(r"([\13\14])")
|
|---|
| 7 | timefunc(10, p.sub, "", s)
|
|---|
| 8 | timefunc(10, p.split, s)
|
|---|
| 9 | timefunc(10, p.findall, s)
|
|---|
| 10 |
|
|---|
| 11 | def timefunc(n, func, *args, **kw):
|
|---|
| 12 | t0 = time.clock()
|
|---|
| 13 | try:
|
|---|
| 14 | for i in range(n):
|
|---|
| 15 | result = func(*args, **kw)
|
|---|
| 16 | return result
|
|---|
| 17 | finally:
|
|---|
| 18 | t1 = time.clock()
|
|---|
| 19 | if n > 1:
|
|---|
| 20 | print n, "times",
|
|---|
| 21 | print func.__name__, "%.3f" % (t1-t0), "CPU seconds"
|
|---|
| 22 |
|
|---|
| 23 | main()
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.