add an extra global that is never defined; this is used to handle names that never...
[pythonc.git] / pythonc.py
blob492da1d9f99c1bad7d609b3f958dbc3b9a6d9594
1 #!/usr/bin/python3
3 import os
4 import subprocess
5 import sys
6 import time
8 def usage():
9 print('usage: %s [-O] <input.py> [args...]' % sys.argv[0])
10 exit(1)
12 args = sys.argv[1:]
14 gcc_flags = ['-g', '-Wall']
15 quiet = False
16 if args and args[0] == '-O':
17 gcc_flags += ['-O3']
18 args = args[1:]
19 if args and args[0] == '-q':
20 quiet = True
21 args = args[1:]
23 if not args:
24 usage()
26 path = args[0]
27 base = os.path.splitext(path)[0]
29 start = time.time()
30 subprocess.check_call(['python3', 'transform.py', path, '%s.cpp' % base])
31 elapsed = time.time() - start
32 if not quiet:
33 print('Transform time: %.4fs' % elapsed)
35 start = time.time()
36 subprocess.check_call(['c++'] + gcc_flags + ['%s.cpp' % base, '-o', base])
37 elapsed = time.time() - start
38 if not quiet:
39 print('Compile time: %.4fs' % elapsed)
41 start = time.time()
42 subprocess.check_call(['./%s' % base] + args[1:])
43 elapsed = time.time() - start
44 if not quiet:
45 print('Run time: %.4fs' % elapsed)