0

I have taken the setup variable as

setup='''import subprocess \
from java_compile import func 
'''

Definition of function whose time i want to measure is:

def func(uid,ppid,j,fn):
    global fwrite
    curr_working_path=os.getcwd()
    rel_path='/var/www/html/abc/temp/'+uid+'/p'+str(ppid)+'/'
    os.chdir(rel_path)
    fdr=open(fwrite,"r")
    fdw=open(str(j)+'.txt',"w")
    subprocess.call(['java',str(fn)],stdin=fdr,stdout=fdw,stderr=subprocess.STDOUT)
    os.chdir(curr_working_path)

And i am calling the timeit functiont

timeit.timeit("func("+uid+","+str(ppid)+","+str(j)+","+fn+")",setup,number=1))

Also java_compile is the file which has two function one check and other one is func. In func check i am calling timeit module to calculate the time for execution of function func. When it tried to debug it i found that it is taking a new line character at the end of setup variable or in the statement, i am unable to understand why such thing is happening?Please help

Vipul
  • 566
  • 5
  • 29
  • Try `setup="import subprocess;from java_compile import func"` – jonrsharpe Jan 29 '15 at 14:37
  • Already tried this but after using this setup works fine but the stmt part of timeit show an extra new line character – Vipul Jan 29 '15 at 14:40
  • It's not quite clear what the problem is; could you show some examples? Why aren't you using Java profiling tools instead? – jonrsharpe Jan 29 '15 at 14:41
  • I have pasted the code on pastebin and the link is given below : (pastebin.com/WZzH6bdx) would really appreciate if you can have a look at it – Vipul Jan 29 '15 at 14:50
  • No, please edit the question to provide a [minimal example](http://stackoverflow.com/help/mcve) of code, input data and outputs. – jonrsharpe Jan 29 '15 at 14:51
  • try: `elapsed = timeit.timeit(functools.partial(func, uid, ppid, j, fn), number=1)` -- note: there is no point to call it with `number=1`. You could use `start = timer(); func(uid, ppid, j, fn); elapsed = timer() - start` instead, where `timer = timeit.default_timer`. – jfs Jan 30 '15 at 13:27

0 Answers0