Python performance profiling (file close)

Posted by user1853986 on Stack Overflow See other posts from Stack Overflow or by user1853986
Published on 2012-11-26T16:36:31Z Indexed on 2012/11/26 17:04 UTC
Read the original article Hit count: 124

Filed under:
|
|
|
|

First of all thanks for your attention. My question is how to reduce the execution time of my code.

Here is the relevant code. The below code is called in iteration from the main.

def call_prism(prism_input_file,random_length):
   prism_output_file = "path.txt"
   cmd = "prism %s -simpath %d %s" % (prism_input_file,random_length,prism_output_file)
   p = os.popen(cmd)
   p.close()
   return prism_output_file


def main(prism_input_file, number_of_strings):
...
  for n in range(number_of_strings):
        prism_output_file = call_prism(prism_input_file,z[n])
        ...

  return

I used statistics from the "profile statistics browser" when I profiled my code. The "file close" system command took the maximum time (14.546 seconds). The call_prism routine is called 10 times. But the number_of_strings is usually in thousands, so, my program takes lot of time to complete.

Let me know if you need more information. By the way I tried with subprocess, too. Thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about Performance