Skip to content

Commit

Permalink
Implement a variant of the executable size 'benchmark' that disables …
Browse files Browse the repository at this point in the history
…exceptions and RTTI.
  • Loading branch information
poletti-marco committed Sep 12, 2018
1 parent bc7a2df commit 88a5230
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
12 changes: 11 additions & 1 deletion extras/benchmark/generate_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def generate_benchmark(
num_components_with_deps,
num_deps,
generate_runtime_bench_code,
use_exceptions=True,
use_rtti=True,
fruit_build_dir=None,
fruit_sources_dir=None,
boost_di_sources_dir=None,
Expand Down Expand Up @@ -129,6 +131,10 @@ def generate_benchmark(
other_compile_flags = []
if generate_debuginfo:
other_compile_flags.append('-g')
if not use_exceptions:
other_compile_flags.append('-fno-exceptions')
if not use_rtti:
other_compile_flags.append('-fno-rtti')
compile_command = '%s -std=%s -MMD -MP -O2 -W -Wall -Werror -DNDEBUG -ftemplate-depth=10000 %s %s' % (compiler, cxx_std, include_flags, ' '.join(other_compile_flags))
link_command = '%s -std=%s -O2 -W -Wall -Werror %s %s' % (compiler, cxx_std, rpath_flags, library_dirs_flags)
# GCC requires passing the -lfruit flag *after* all object files to be linked for some reason.
Expand Down Expand Up @@ -165,6 +171,8 @@ def main():
parser.add_argument('--use-normalized-component', default='false', help='Set this to \'true\' to create a NormalizedComponent and create the injector from that. Only relevant when --di_library=fruit and --generate-runtime-bench-code=false.')
parser.add_argument('--generate-runtime-bench-code', default='true', help='Set this to \'false\' for compile benchmarks.')
parser.add_argument('--generate-debuginfo', default='false', help='Set this to \'true\' to generate debugging information (-g).')
parser.add_argument('--use-exceptions', default='true', help='Set this to \'false\' to disable exceptions.')
parser.add_argument('--use-rtti', default='true', help='Set this to \'false\' to disable RTTI.')

args = parser.parse_args()

Expand Down Expand Up @@ -206,7 +214,9 @@ def main():
use_new_delete=(args.use_new_delete == 'true'),
use_interfaces=(args.use_interfaces == 'true'),
use_normalized_component=(args.use_normalized_component == 'true'),
generate_runtime_bench_code=(args.generate_runtime_bench_code == 'true'))
generate_runtime_bench_code=(args.generate_runtime_bench_code == 'true'),
use_exceptions=(args.use_exceptions == 'true'),
use_rtti=(args.use_rtti == 'true'))


if __name__ == "__main__":
Expand Down
43 changes: 43 additions & 0 deletions extras/benchmark/run_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ def prepare(self):
def run(self):
return self.run_executable_size_benchmark()

# This is not really a 'benchmark', but we consider it as such to reuse the benchmark infrastructure.
class ExecutableSizeBenchmarkWithoutExceptionsAndRtti(ExecutableSizeBenchmark):
def __init__(self, **kwargs):
super().__init__(use_exceptions=False,
use_rtti=False,
**kwargs)

class FruitCompileTimeBenchmark(CompileTimeBenchmark):
def __init__(self, fruit_sources_dir, **kwargs):
super().__init__(di_library='fruit',
Expand Down Expand Up @@ -415,6 +422,13 @@ def __init__(self, fruit_sources_dir, **kwargs):
fruit_sources_dir=fruit_sources_dir,
**kwargs)

# This is not really a 'benchmark', but we consider it as such to reuse the benchmark infrastructure.
class FruitExecutableSizeBenchmarkWithoutExceptionsAndRtti(ExecutableSizeBenchmarkWithoutExceptionsAndRtti):
def __init__(self, fruit_sources_dir, **kwargs):
super().__init__(di_library='fruit',
path_to_code_under_test=fruit_sources_dir,
fruit_sources_dir=fruit_sources_dir,
**kwargs)

class BoostDiCompileTimeBenchmark(CompileTimeBenchmark):
def __init__(self, boost_di_sources_dir, **kwargs):
Expand Down Expand Up @@ -452,6 +466,14 @@ def __init__(self, boost_di_sources_dir, **kwargs):
boost_di_sources_dir=boost_di_sources_dir,
**kwargs)

# This is not really a 'benchmark', but we consider it as such to reuse the benchmark infrastructure.
class BoostDiExecutableSizeBenchmarkWithoutExceptionsAndRtti(ExecutableSizeBenchmarkWithoutExceptionsAndRtti):
def __init__(self, boost_di_sources_dir, **kwargs):
super().__init__(di_library='boost_di',
path_to_code_under_test=boost_di_sources_dir,
boost_di_sources_dir=boost_di_sources_dir,
**kwargs)

class SimpleDiCompileTimeBenchmark(CompileTimeBenchmark):
def __init__(self, **kwargs):
super().__init__(di_library='none',
Expand All @@ -478,6 +500,12 @@ def __init__(self, **kwargs):
super().__init__(di_library='none',
**kwargs)

# This is not really a 'benchmark', but we consider it as such to reuse the benchmark infrastructure.
class SimpleDiExecutableSizeBenchmarkWithoutExceptionsAndRtti(ExecutableSizeBenchmarkWithoutExceptionsAndRtti):
def __init__(self, **kwargs):
super().__init__(di_library='none',
**kwargs)

class SimpleDiWithInterfacesCompileTimeBenchmark(SimpleDiCompileTimeBenchmark):
def __init__(self, **kwargs):
super().__init__(use_interfaces=True, **kwargs)
Expand All @@ -499,6 +527,11 @@ class SimpleDiWithInterfacesExecutableSizeBenchmark(SimpleDiExecutableSizeBenchm
def __init__(self, **kwargs):
super().__init__(use_interfaces=True, **kwargs)

# This is not really a 'benchmark', but we consider it as such to reuse the benchmark infrastructure.
class SimpleDiWithInterfacesExecutableSizeBenchmarkWithoutExceptionsAndRtti(SimpleDiExecutableSizeBenchmarkWithoutExceptionsAndRtti):
def __init__(self, **kwargs):
super().__init__(use_interfaces=True, **kwargs)

class SimpleDiWithInterfacesAndNewDeleteCompileTimeBenchmark(SimpleDiWithInterfacesCompileTimeBenchmark):
def __init__(self, **kwargs):
super().__init__(use_new_delete=True, **kwargs)
Expand All @@ -520,6 +553,11 @@ class SimpleDiWithInterfacesAndNewDeleteExecutableSizeBenchmark(SimpleDiWithInte
def __init__(self, **kwargs):
super().__init__(use_new_delete=True, **kwargs)

# This is not really a 'benchmark', but we consider it as such to reuse the benchmark infrastructure.
class SimpleDiWithInterfacesAndNewDeleteExecutableSizeBenchmarkWithoutExceptionsAndRtti(SimpleDiWithInterfacesExecutableSizeBenchmarkWithoutExceptionsAndRtti):
def __init__(self, **kwargs):
super().__init__(use_new_delete=True, **kwargs)


def round_to_significant_digits(n, num_significant_digits):
if n <= 0:
Expand Down Expand Up @@ -711,6 +749,7 @@ def main():
'fruit_startup_time': FruitStartupTimeBenchmark,
'fruit_startup_time_with_normalized_component': FruitStartupTimeWithNormalizedComponentBenchmark,
'fruit_executable_size': FruitExecutableSizeBenchmark,
'fruit_executable_size_without_exceptions_and_rtti': FruitExecutableSizeBenchmarkWithoutExceptionsAndRtti,
}[benchmark_name]
benchmark = benchmark_class(
benchmark_definition=benchmark_definition,
Expand All @@ -723,6 +762,7 @@ def main():
'boost_di_run_time': BoostDiRunTimeBenchmark,
'boost_di_startup_time': BoostDiStartupTimeBenchmark,
'boost_di_executable_size': BoostDiExecutableSizeBenchmark,
'boost_di_executable_size_without_exceptions_and_rtti': BoostDiExecutableSizeBenchmarkWithoutExceptionsAndRtti,
}[benchmark_name]
benchmark = benchmark_class(
benchmark_definition=benchmark_definition,
Expand All @@ -734,16 +774,19 @@ def main():
'simple_di_run_time': SimpleDiRunTimeBenchmark,
'simple_di_startup_time': SimpleDiStartupTimeBenchmark,
'simple_di_executable_size': SimpleDiExecutableSizeBenchmark,
'simple_di_executable_size_without_exceptions_and_rtti': SimpleDiExecutableSizeBenchmarkWithoutExceptionsAndRtti,
'simple_di_with_interfaces_compile_time': SimpleDiWithInterfacesCompileTimeBenchmark,
'simple_di_with_interfaces_incremental_compile_time': SimpleDiWithInterfacesIncrementalCompileTimeBenchmark,
'simple_di_with_interfaces_run_time': SimpleDiWithInterfacesRunTimeBenchmark,
'simple_di_with_interfaces_startup_time': SimpleDiWithInterfacesStartupTimeBenchmark,
'simple_di_with_interfaces_executable_size': SimpleDiWithInterfacesExecutableSizeBenchmark,
'simple_di_with_interfaces_executable_size_without_exceptions_and_rtti': SimpleDiWithInterfacesExecutableSizeBenchmarkWithoutExceptionsAndRtti,
'simple_di_with_interfaces_and_new_delete_compile_time': SimpleDiWithInterfacesAndNewDeleteCompileTimeBenchmark,
'simple_di_with_interfaces_and_new_delete_incremental_compile_time': SimpleDiWithInterfacesAndNewDeleteIncrementalCompileTimeBenchmark,
'simple_di_with_interfaces_and_new_delete_run_time': SimpleDiWithInterfacesAndNewDeleteRunTimeBenchmark,
'simple_di_with_interfaces_and_new_delete_startup_time': SimpleDiWithInterfacesAndNewDeleteStartupTimeBenchmark,
'simple_di_with_interfaces_and_new_delete_executable_size': SimpleDiWithInterfacesAndNewDeleteExecutableSizeBenchmark,
'simple_di_with_interfaces_and_new_delete_executable_size_without_exceptions_and_rtti': SimpleDiWithInterfacesAndNewDeleteExecutableSizeBenchmarkWithoutExceptionsAndRtti,
}[benchmark_name]
benchmark = benchmark_class(
benchmark_definition=benchmark_definition)
Expand Down

0 comments on commit 88a5230

Please sign in to comment.