| 1 | #!/usr/bin/env python2
|
| 2 | """
|
| 3 | varargs.py
|
| 4 | """
|
| 5 | from __future__ import print_function
|
| 6 |
|
| 7 | import os
|
| 8 | import sys
|
| 9 |
|
| 10 | from mycpp import mylib
|
| 11 | from mycpp.mylib import log, print_stderr
|
| 12 |
|
| 13 | from typing import Any
|
| 14 |
|
| 15 | def run_tests():
|
| 16 | # type: () -> None
|
| 17 |
|
| 18 | log('constant string')
|
| 19 |
|
| 20 | print_stderr('stderr_line')
|
| 21 |
|
| 22 | # Positional args
|
| 23 | log("log %d %s", 42, "LL")
|
| 24 |
|
| 25 | # Escaped %%
|
| 26 | log("[%%] %d %s", 42, "LL")
|
| 27 |
|
| 28 |
|
| 29 | def run_benchmarks():
|
| 30 | # type: () -> None
|
| 31 |
|
| 32 | # Test the interpreted format strings vs. the compiler!
|
| 33 | # This might not be enough to get over startup time
|
| 34 | r = "'repr'" + ' "repr"'
|
| 35 | for i in xrange(10000):
|
| 36 | log("[%%] %d %s %r", 123456789, "string", r)
|
| 37 |
|
| 38 |
|
| 39 | if __name__ == '__main__':
|
| 40 | if os.getenv('BENCHMARK'):
|
| 41 | log('Benchmarking...')
|
| 42 | run_benchmarks()
|
| 43 | else:
|
| 44 | run_tests()
|