Skip to content

Commit f3b09e1

Browse files
Per NordlöwPer Nordlöw
Per Nordlöw
authored and
Per Nordlöw
committed
More powerful format support for --languages flag
1 parent 138dd20 commit f3b09e1

File tree

2 files changed

+94
-81
lines changed

2 files changed

+94
-81
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ for suitable values of `$FUNCTION_COUNT` and `FUNCTION_DEPTH` or simply
4848

4949
for defaulted values of all the parameters.
5050

51-
A subset of languages to benchmark can be chosen as, for instance,
51+
A subset of languages combined with set of compilers to benchmark can be chosen
52+
as, for instance,
5253

53-
./benchmark --languages=C++,D,Rust
54+
./benchmark --languages=C:tcc,C:gcc-12,C++,D:dmd,D:ldmd2,D:gdc-12,Rust
5455

5556
This will generate code into the directory `generated` and then, for each
5657
combination of language, operation type and compiler, run the supported

benchmark

Lines changed: 91 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ TEMPLATED_SUPPORTED_LANGUAGES = ['C++', 'Java', 'D', 'Swift', 'Vox', 'Rust', 'Zi
2626
SUPPORTED_OPERATIONS = ['Check', 'Compile', 'Build']
2727
DEFAULT_PROGRAM_NAME = 'main'
2828

29+
C_EXES = ['tcc', 'gcc', 'clang',]
30+
D_EXES = ['dmd', 'ldmd2', 'gdc',]
31+
RUST_EXES = ['rustc']
32+
2933
C_WARN_FLAGS = ['-Wall', '-Wextra', '-Wno-c++11-extensions']
3034

3135
RUSTC_NO_WARNINGS_FLAGS = ['-A', 'warnings'] # flags that disable warnings for `rustc`
@@ -36,9 +40,9 @@ JULIA_COMPILE_FLAGS = ['-O0'] # See: https://github.com/JuliaLang/julia/issues/
3640

3741
ROOT_PATH = 'generated'
3842
RANGE = range(5, 15)
39-
VERSIONS = [""] + [f"-{i}" for i in RANGE]
43+
VERSIONS = [''] + [f"-{i}" for i in RANGE]
4044

41-
HOME = os.path.expanduser("~") # instead of home = os.getenv('HOME') that doesn’t work on Windows
45+
HOME = os.path.expanduser('~') # instead of home = os.getenv('HOME') that doesn’t work on Windows
4246

4347

4448
class Row: # TODO use
@@ -309,18 +313,17 @@ def main():
309313
split = language_exes_spec.split(':')
310314
if len(split) == 2:
311315
language = split[0]
312-
exes = split[1]
316+
exes = split[1]. split(',')
313317
else:
314318
language = split[0]
315-
exes = Null
319+
exes = []
316320
if language not in SUPPORTED_LANGUAGES:
317321
print('Warning: Ignoring unsupported language ' + language)
318322
continue
319323
if language in args.language_exes:
320-
args.language_exes[language] += tuple(exes.split(','))
324+
args.language_exes[language] += exes
321325
else:
322-
args.language_exes[language] = tuple(exes.split(','))
323-
print("args.language_exes:", args.language_exes)
326+
args.language_exes[language] = exes
324327

325328
args.operations = list(map(lambda x: x.capitalize(), args.operations.split(','))) # into a list of capitalized names
326329
filtered_operations = []
@@ -444,9 +447,9 @@ def main():
444447
print(markdown_table(TABLE_TITLES, results))
445448

446449

447-
def match_lang(args, lang, exe_name):
450+
def match_lang_exe(args, lang, exe_name):
448451
try:
449-
if exe_name not in args.language_exes[lang]:
452+
if args.language_exes[lang] and exe_name not in args.language_exes[lang]:
450453
return None
451454
except KeyError:
452455
pass
@@ -456,7 +459,7 @@ def match_lang(args, lang, exe_name):
456459
def benchmark_Ada_using_gcc(results, lang, code_paths, args, op, templated):
457460
exe_flags = ['compile'] if op == 'Build' else ['check']
458461
for gcc_version in VERSIONS:
459-
exe = match_lang(args, lang, 'gnat' + str(gcc_version))
462+
exe = match_lang_exe(args, lang, 'gnat' + str(gcc_version))
460463
if exe:
461464
version = get_version(sp.run([exe, '--version'], stdout=sp.PIPE))
462465
compile_file(code_paths,
@@ -491,7 +494,7 @@ def benchmark_C_using_cproc(results, lang, code_paths, args, op, templated):
491494
return False
492495
else:
493496
return None
494-
exe = match_lang(args, lang, 'cproc')
497+
exe = match_lang_exe(args, lang, 'cproc')
495498
if exe:
496499
version = 'unknown'
497500
compile_file(code_paths,
@@ -519,7 +522,7 @@ def benchmark_C_using_tcc(results, lang, code_paths, args, op, templated):
519522
out_flag_and_exe = ['-o', out_binary(lang)]
520523
else:
521524
return None
522-
exe = match_lang(args, lang, 'tcc')
525+
exe = match_lang_exe(args, lang, 'tcc')
523526
if exe:
524527
version = get_version(sp.run([exe, '-v'], stdout=sp.PIPE))
525528
compile_file(code_paths,
@@ -556,9 +559,9 @@ def benchmark_C_and_Cxx_using_gcc(results, lang, code_paths, args, op, templated
556559
return none
557560
for gcc_version in VERSIONS:
558561
if lang == 'C':
559-
exe = match_lang(args, lang, 'gcc' + str(gcc_version))
562+
exe = match_lang_exe(args, lang, 'gcc' + str(gcc_version))
560563
elif lang == 'C++':
561-
exe = match_lang(args, lang, 'g++' + str(gcc_version))
564+
exe = match_lang_exe(args, lang, 'g++' + str(gcc_version))
562565
else:
563566
return None
564567
if exe:
@@ -583,9 +586,9 @@ def benchmark_C_and_Cxx_using_clang(results, lang, code_paths, args, op, templat
583586
C_CLANG_FLAGS = C_WARN_FLAGS + ['-fno-color-diagnostics', '-fno-caret-diagnostics', '-fno-diagnostics-show-option']
584587
for clang_version in VERSIONS:
585588
if lang == 'C':
586-
exe = match_lang(args, lang, 'clang' + str(clang_version))
589+
exe = match_lang_exe(args, lang, 'clang' + str(clang_version))
587590
elif lang == 'C++':
588-
exe = match_lang(args, lang, 'clang' + str(clang_version))
591+
exe = match_lang_exe(args, lang, 'clang' + str(clang_version))
589592
else:
590593
return None
591594
if exe:
@@ -621,54 +624,57 @@ def benchmark_D(results, code_paths, args, op, templated, use_dips):
621624
else:
622625
return None
623626

624-
# dmd
625-
exe = match_lang(args, lang, 'dmd')
626-
if exe:
627-
version = get_version(sp.run([exe, '--version'], stdout=sp.PIPE))
628-
compile_file(code_paths=code_paths,
629-
out_flag_and_exe=['-of=' + out_binary(lang)] if op == 'Build' else [],
630-
exe=exe,
631-
runner=True,
632-
exe_flags=d_flags + exe_flags,
633-
args=args,
634-
op=op,
635-
compiler_version=version,
636-
lang=lang,
637-
templated=templated,
638-
results=results)
639-
640-
# ldmd2
641-
exe = match_lang(args, lang, 'ldmd2')
642-
if exe:
643-
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[6][1:-2]
644-
compile_file(code_paths=code_paths,
645-
out_flag_and_exe=['-of=' + out_binary(lang)] if op == 'Build' else [],
646-
exe=exe,
647-
runner=True,
648-
exe_flags=d_flags + exe_flags,
649-
args=args,
650-
op=op,
651-
compiler_version=version,
652-
lang=lang,
653-
templated=templated,
654-
results=results)
627+
try:
628+
exes = args.language_exes[lang]
629+
except KeyError:
630+
return
631+
if not exes:
632+
exes = D_EXES
655633

656-
# gdc
657-
exe = match_lang(args, lang, 'gdc')
658-
if exe:
659-
exe_flags = ['-fsyntax-only'] if op == 'Check' else []
660-
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[3]
661-
compile_file(code_paths=code_paths,
662-
out_flag_and_exe=['-o' + out_binary(lang)] if op == 'Build' else [],
663-
exe=exe,
664-
runner=True,
665-
exe_flags=exe_flags,
666-
args=args,
667-
op=op,
668-
compiler_version=version,
669-
lang=lang,
670-
templated=templated,
671-
results=results)
634+
# dmd
635+
for exe in filter(lambda exe: which(exe), exes):
636+
if not which(exe):
637+
continue
638+
if exe.startswith('dmd'):
639+
version = get_version(sp.run([exe, '--version'], stdout=sp.PIPE))
640+
compile_file(code_paths=code_paths,
641+
out_flag_and_exe=['-of=' + out_binary(lang)] if op == 'Build' else [],
642+
exe=exe,
643+
runner=True,
644+
exe_flags=d_flags + exe_flags,
645+
args=args,
646+
op=op,
647+
compiler_version=version,
648+
lang=lang,
649+
templated=templated,
650+
results=results)
651+
elif exe.startswith('ldmd2'):
652+
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[6][1:-2]
653+
compile_file(code_paths=code_paths,
654+
out_flag_and_exe=['-of=' + out_binary(lang)] if op == 'Build' else [],
655+
exe=exe,
656+
runner=True,
657+
exe_flags=d_flags + exe_flags,
658+
args=args,
659+
op=op,
660+
compiler_version=version,
661+
lang=lang,
662+
templated=templated,
663+
results=results)
664+
elif exe.startswith('gdc'):
665+
exe_flags = ['-fsyntax-only'] if op == 'Check' else []
666+
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[3]
667+
compile_file(code_paths=code_paths,
668+
out_flag_and_exe=['-o' + out_binary(lang)] if op == 'Build' else [],
669+
exe=exe,
670+
runner=True,
671+
exe_flags=exe_flags,
672+
args=args,
673+
op=op,
674+
compiler_version=version,
675+
lang=lang,
676+
templated=templated,
677+
results=results)
672678

673679

674680
def benchmark_Vox(results, code_paths, args, op, templated):
@@ -683,7 +689,7 @@ def benchmark_Vox(results, code_paths, args, op, templated):
683689
out_flag_and_exe = ['--of=' + out_binary(lang)]
684690
else:
685691
return None
686-
exe = match_lang(args, lang, 'vox')
692+
exe = match_lang_exe(args, lang, 'vox')
687693
if exe:
688694
compile_file(code_paths,
689695
out_flag_and_exe=out_flag_and_exe,
@@ -700,7 +706,7 @@ def benchmark_Vox(results, code_paths, args, op, templated):
700706

701707
def benchmark_Mono(results, code_paths, args, op, templated):
702708
lang = 'C#'
703-
exe = match_lang(args, lang, 'mcs')
709+
exe = match_lang_exe(args, lang, 'mcs')
704710
if exe:
705711
exe_flags = ['-target:exe'] + ([] if op == 'Build' else [''])
706712
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[4]
@@ -739,7 +745,7 @@ def benchmark_Go_using_go(results, code_paths, args, op, templated):
739745
out_flag_and_exe = []
740746
else:
741747
return None
742-
exe = match_lang(args, lang, exe)
748+
exe = match_lang_exe(args, lang, exe)
743749
if exe:
744750
compile_file(code_paths,
745751
out_flag_and_exe=out_flag_and_exe,
@@ -757,7 +763,7 @@ def benchmark_Go_using_go(results, code_paths, args, op, templated):
757763
def benchmark_Go_using_gccgo(results, code_paths, args, op, templated):
758764
lang = 'Go'
759765
for gccgo_version in VERSIONS:
760-
exe = match_lang(args, lang, 'gccgo' + str(gccgo_version))
766+
exe = match_lang_exe(args, lang, 'gccgo' + str(gccgo_version))
761767
if exe:
762768
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[3]
763769
compile_file(code_paths,
@@ -775,7 +781,7 @@ def benchmark_Go_using_gccgo(results, code_paths, args, op, templated):
775781

776782
def benchmark_Swift(results, code_paths, args, op, templated):
777783
lang = 'Swift'
778-
exe = (match_lang(args, lang, 'swiftc') or
784+
exe = (match_lang_exe(args, lang, 'swiftc') or
779785
which(os.path.join(HOME, '.local/swift-5.3.3-RELEASE-ubuntu20.04/usr/bin/swiftc')))
780786
if op == 'Build':
781787
exe_flags = ['']
@@ -801,9 +807,9 @@ def benchmark_Swift(results, code_paths, args, op, templated):
801807
def benchmark_OCaml(results, code_paths, args, op, templated, bytecode):
802808
lang = 'OCaml'
803809
if bytecode:
804-
exe = match_lang(args, lang, 'ocamlc')
810+
exe = match_lang_exe(args, lang, 'ocamlc')
805811
else:
806-
exe = match_lang(args, lang, 'ocamlopt')
812+
exe = match_lang_exe(args, lang, 'ocamlopt')
807813
if exe:
808814
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[0]
809815
compile_file(code_paths,
@@ -823,7 +829,7 @@ def benchmark_OCaml(results, code_paths, args, op, templated, bytecode):
823829

824830
def benchmark_V(results, code_paths, args, op, templated):
825831
lang = 'V' # vlang.io
826-
exe = match_lang(args, lang, 'v')
832+
exe = match_lang_exe(args, lang, 'v')
827833
if exe:
828834
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[1]
829835
vlang_backends = ['native', 'c', 'js', 'x64', 'v2', 'experimental']
@@ -842,7 +848,7 @@ def benchmark_V(results, code_paths, args, op, templated):
842848

843849
def benchmark_C3(results, code_paths, args, op, templated):
844850
lang = 'C3'
845-
exe = (match_lang(args, lang, 'c3c') or
851+
exe = (match_lang_exe(args, lang, 'c3c') or
846852
which(os.path.join(HOME, 'ware/c3c/build/c3c')))
847853
if exe:
848854
exe_flags = ['-O0']
@@ -870,7 +876,7 @@ def benchmark_C3(results, code_paths, args, op, templated):
870876

871877
def benchmark_Zig(results, code_paths, args, op, templated):
872878
lang = 'Zig'
873-
exe = match_lang(args, lang, 'zig')
879+
exe = match_lang_exe(args, lang, 'zig')
874880
if exe:
875881
version = sp.run([exe, 'version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[0]
876882
compile_file(code_paths,
@@ -887,7 +893,7 @@ def benchmark_Zig(results, code_paths, args, op, templated):
887893

888894
def benchmark_Nim(results, code_paths, args, op, templated, exe_flags=None):
889895
lang = 'Nim'
890-
exe = match_lang(args, lang, 'nim')
896+
exe = match_lang_exe(args, lang, 'nim')
891897

892898
tcc_exe = which('tcc')
893899
exe_flags = ['--hints:off', '--checks:off', '--stacktrace:off'] + ([('--cc:tcc')] if tcc_exe else [])
@@ -930,12 +936,18 @@ def benchmark_Rust(results, code_paths, args, op, templated):
930936
else:
931937
rustup_channels = [None]
932938

939+
try:
940+
exes = args.language_exes[lang]
941+
except KeyError:
942+
return
943+
if not exes:
944+
exes = RUST_EXES
945+
933946
for channel in rustup_channels:
934947
if rustup_exe is not None:
935948
set_rustup_channel(channel)
936949

937-
exe = match_lang(args, lang, 'rustc')
938-
if exe:
950+
for exe in exes:
939951
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[1]
940952
if op == 'Check':
941953
# `cargo check` uses `rustc --emit=metadata`
@@ -960,7 +972,7 @@ def benchmark_Rust(results, code_paths, args, op, templated):
960972

961973
def benchmark_Java(results, code_paths, args, op, templated):
962974
lang = 'Java'
963-
exe = match_lang(args, lang, 'javac')
975+
exe = match_lang_exe(args, lang, 'javac')
964976
if exe:
965977
try:
966978
task = sp.run([exe, '-version'],
@@ -986,7 +998,7 @@ def benchmark_Java(results, code_paths, args, op, templated):
986998

987999
def benchmark_Pareas(results, code_paths, args, op, templated):
9881000
lang = 'Pareas'
989-
exe = match_lang(args, lang, 'pareas')
1001+
exe = match_lang_exe(args, lang, 'pareas')
9901002
if exe:
9911003
compile_file(code_paths,
9921004
out_flag_and_exe=['-o', out_binary(lang)],
@@ -1003,7 +1015,7 @@ def benchmark_Pareas(results, code_paths, args, op, templated):
10031015

10041016
def benchmark_Julia(results, code_paths, args, op, templated):
10051017
lang = 'Julia'
1006-
exe = match_lang(args, lang, 'julia')
1018+
exe = match_lang_exe(args, lang, 'julia')
10071019
if exe:
10081020
version = sp.run([exe, '--version'], stdout=sp.PIPE).stdout.decode('utf-8').split()[2]
10091021
compile_file(code_paths,

0 commit comments

Comments
 (0)