I have the following example code which resembles the main code I am working on. The main bottleneck I see is in the function calls call_fun. Is there a way to speed this up ? ..example: not using a dictionary object self._d but something else for function lookup? In the main code, the list "names" is pretty big. You can enable the commented out print statements for a quick understanding of the code (... but please be sure to change i in range(500000) to i in range(1) if you want to print output)
import time
names = [ ('f_a', ([1,1],)), ('f_b', ([3,4],) ) ]
class A(object):
    def __init__(self):        
        self._d = {}
        for n in names:            
            self._d[n[0]] = getattr(self, n[0])
    def call_fun(self, k):       
        #print " In call_fun: k: ", k
        return self._d[k[0]](*k[1])
    def f_a(self, vals):
        #print " I am here in f_a.. vals=", vals
        v =  2*vals
        return v
    def f_b(self, vals):
        v =  3*vals
        return v
# Run the code
start = time.clock()
a = A()
print "names[0]:", names[0]
for i in range(5000000):
    a.call_fun((names[0]))
print "done, elapsed wall clock time (win32) in seconds: " , time.clock() - start
Here is the profiling output: python -m cProfile --sort cumulative foo.py
    10000009 function calls in 5.614 seconds
   Ordered by: cumulative time
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    2.066    2.066    5.614    5.614 foo.py:1(<module>)
  5000000    2.345    0.000    3.412    0.000 foo.py:11(call_fun)
  5000000    1.067    0.000    1.067    0.000 foo.py:15(f_a)
        1    0.135    0.135    0.135    0.135 {range}
        1    0.000    0.000    0.000    0.000 foo.py:6(__init__)
        2    0.000    0.000    0.000    0.000 {time.clock}
        1    0.000    0.000    0.000    0.000 foo.py:5(A)
        2    0.000    0.000    0.000    0.000 {getattr}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
 
     
     
     
     
    