#!/usr/bin/python import os import string decl = """extern boost::function hook; """ #decl = """extern boost::function hook; #extern boost::function hook2; #extern boost::function hook3; #extern boost::function hook4; #""" call = " hook(10);\n"; #call = " hook(10); hook2(10);hook3(0);hook4(0);\n"; def run_test(num_calls, compiler_command): f = open("function_test.cpp", "w") f.write("""#include %s void do_it() {""" % (decl)) for i in range(0, num_calls): f.write(call) f.write("}\n") f.close() os.system(compiler_command + " -c -save-temps -I /home/ghost/Work/boost function_test.cpp") nm = os.popen("nm -S function_test.o") for l in nm: if string.find(l, "Z5do_itv") != -1: break size = int(string.split(l)[1], 16) return size def run_tests(range, compiler_command): prev_size = None for num in range: size = run_test(num, compiler_command) if prev_size: print "%2d calls: %5d bytes (+ %d)" % (num, size, size-prev_size) else: print "%2d calls: %5d bytes" % (num, size) prev_size = size if __name__ == '__main__': for compiler in [ "g++-3.3 -Os", "g++-3.3 -O3", "g++-3.4 -Os", "g++-3.4 -O3"]: print "****", compiler, "****" run_tests(range(1, 40), compiler)