| 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 | CONST = "myconst"
 | 
| 16 | 
 | 
| 17 | 
 | 
| 18 | def run_tests():
 | 
| 19 |     # type: () -> None
 | 
| 20 | 
 | 
| 21 |     log('constant string')
 | 
| 22 | 
 | 
| 23 |     print_stderr('stderr_line')
 | 
| 24 | 
 | 
| 25 |     # Positional args
 | 
| 26 |     log("log %d %s", 42, "LL")
 | 
| 27 | 
 | 
| 28 |     # Escaped %%
 | 
| 29 |     log("[%%] %d %s", 42, "LL")
 | 
| 30 | 
 | 
| 31 |     log(CONST)
 | 
| 32 | 
 | 
| 33 | 
 | 
| 34 | def run_benchmarks():
 | 
| 35 |     # type: () -> None
 | 
| 36 | 
 | 
| 37 |     # Test the interpreted format strings vs. the compiler!
 | 
| 38 |     # This might not be enough to get over startup time
 | 
| 39 |     r = "'repr'" + ' "repr"'
 | 
| 40 |     for i in xrange(10000):
 | 
| 41 |         log("[%%] %d %s %r", 123456789, "string", r)
 | 
| 42 | 
 | 
| 43 | 
 | 
| 44 | if __name__ == '__main__':
 | 
| 45 |     if os.getenv('BENCHMARK'):
 | 
| 46 |         log('Benchmarking...')
 | 
| 47 |         run_benchmarks()
 | 
| 48 |     else:
 | 
| 49 |         run_tests()
 |