File: program_options_size_test.py

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (53 lines) | stat: -rw-r--r-- 1,415 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python

import os
import string


call = "   hook(10);\n";
call = "   hook(10); hook2(10);hook3(0);hook4(0);\n";

def run_test(num_calls, compiler_command):
   f = open("program_options_test.cpp", "w")
   f.write("""#include <boost/program_options.hpp>
using namespace boost::program_options;   

void do_it()
{
   boost::program_options::options_description desc;
   desc.add_options()
""")
   for i in range(0, num_calls):
      f.write("(\"opt%d\", value<int>())\n")
   f.write(";\n}\n")   
   f.close()
   os.system(compiler_command + " -c -save-temps -I /home/ghost/Work/boost-rc program_options_test.cpp")

   nm = os.popen("nm -S program_options_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):

   last_size = None
   first_size = None
   for num in range:
      size = run_test(num, compiler_command)
      if last_size:
         print "%2d calls: %5d bytes (+ %d)" % (num, size, size-last_size)
      else:
         print "%2d calls: %5d bytes" % (num, size)
         first_size = size
      last_size = size
   print "Avarage: ", (last_size-first_size)/(range[-1]-range[0])

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, 20), compiler)