OILS / mycpp / examples / varargs.py View on Github | oilshell.org

49 lines, 23 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
15CONST = "myconst"
16
17
18def 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
34def 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
44if __name__ == '__main__':
45 if os.getenv('BENCHMARK'):
46 log('Benchmarking...')
47 run_benchmarks()
48 else:
49 run_tests()