OILS / mycpp / examples / varargs.py View on Github | oils.pub

44 lines, 21 significant
1#!/usr/bin/env python2
2"""
3varargs.py
4"""
5from __future__ import print_function
6
7import os
8import sys
9
10from mycpp import mylib
11from mycpp.mylib import log, print_stderr
12
13from typing import Any
14
15def 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
29def 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
39if __name__ == '__main__':
40 if os.getenv('BENCHMARK'):
41 log('Benchmarking...')
42 run_benchmarks()
43 else:
44 run_tests()