Skip to content

Instantly share code, notes, and snippets.

@dabrahams
Created September 4, 2009 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dabrahams/181068 to your computer and use it in GitHub Desktop.
Save dabrahams/181068 to your computer and use it in GitHub Desktop.
# Copyright David Abrahams 2009. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
import os
import sys
def compile(depth, throw=False, catch=False, exception_spec=False, eh_enabled=True):
print 'compiling...',
sys.stdout.flush()
THROW = throw and '-DTHROW' or ''
CATCH = catch and '-DCATCH' or ''
EXCEPTION_SPEC = exception_spec and '-DEXCEPTION_SPEC' or ''
EH = eh_enabled and '-fexceptions' or '-fno-exceptions'
depth = depth+10
os.system('g++-4.4 -ftemplate-depth-%(depth)d -O3 eh-test.cpp -DDEPTH=%(depth)d %(THROW)s %(CATCH)s %(EXCEPTION_SPEC)s %(EH)s -o eh-test' % locals())
print 'done'
sys.stdout.flush()
def test(depth, throw=False, catch=False, exception_spec=False, eh_enabled=True):
compile(depth, throw, catch, exception_spec)
print 'depth =', depth
sys.stdout.flush()
os.system('ls -l ./eh-test')
os.system('sh -c "time ./eh-test" 2>&1 | grep luser') # warm up cache
os.system('sh -c "time ./eh-test" 2>&1 | grep user')
os.system('sh -c "time ./eh-test" 2>&1 | grep user')
print 20*'-'
for throw,catch,exception_spec,eh_enabled,comment in [
(False,False,False,False,'EH disabled - should be fastest'),
(False,False,False,True, 'turn on EH - shows penalty for ability to unwind dtors'),
(False,True,False,True, 'add a catch block'),
(False,True,True,True, 'add empty exception specifications'),
(True,True,False,True, 'remove exception spec and actually throw something')
]:
print 40*'='
print comment
print '; '.join([x+' = %('+x+')s' for x in 'throw', 'catch', 'exception_spec', 'eh_enabled']) % locals()
print 40*'='
for exp in range(0,5):
test(10**exp, throw,catch,exception_spec,eh_enabled);
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment