program_options_size_test.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/python
  2. import os
  3. import string
  4. call = " hook(10);\n";
  5. call = " hook(10); hook2(10);hook3(0);hook4(0);\n";
  6. def run_test(num_calls, compiler_command):
  7. f = open("program_options_test.cpp", "w")
  8. f.write("""#include <boost/program_options.hpp>
  9. using namespace boost::program_options;
  10. void do_it()
  11. {
  12. boost::program_options::options_description desc;
  13. desc.add_options()
  14. """)
  15. for i in range(0, num_calls):
  16. f.write("(\"opt%d\", value<int>())\n")
  17. f.write(";\n}\n")
  18. f.close()
  19. os.system(compiler_command + " -c -save-temps -I /home/ghost/Work/Boost/boost-svn program_options_test.cpp")
  20. nm = os.popen("nm -S program_options_test.o")
  21. for l in nm:
  22. if string.find(l, "Z5do_itv") != -1:
  23. break
  24. size = int(string.split(l)[1], 16)
  25. return size
  26. def run_tests(range, compiler_command):
  27. last_size = None
  28. first_size = None
  29. for num in range:
  30. size = run_test(num, compiler_command)
  31. if last_size:
  32. print "%2d calls: %5d bytes (+ %d)" % (num, size, size-last_size)
  33. else:
  34. print "%2d calls: %5d bytes" % (num, size)
  35. first_size = size
  36. last_size = size
  37. print "Avarage: ", (last_size-first_size)/(range[-1]-range[0])
  38. if __name__ == '__main__':
  39. for compiler in [ "g++ -Os", "g++ -O3"]:
  40. print "****", compiler, "****"
  41. run_tests(range(1, 20), compiler)