I have a script in Python which do some computations. When I run this script in console it takes about 7 minutes to complete but when I run it thought Java shell it takes three times longer. I use following code to execute the script in Java:
this.p = Runtime.getRuntime().exec("script.py --batch", envp);
this.input = new BufferedReader(new InputStreamReader(p.getInputStream()));
this.output = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
this.error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
Do you have any suggestion why the Python script runs three time longer in Java than in a console?
update (29.12.2010)
The computation goes as follow:
Later there is a series of communications between Java and Python but it takes only several second.
update (29.12.2010)
Thank you for all your comments and suggestions. It took one working day to find out that my assumption was wrong. The code I used had 'a bug' and in fact different computation were performed in console and in shell. When I fixed it the computation time was the same.
Summary: The computation time of a script run in console and in Java shell is almost the same. The additional time for initialize Java VM and IO communication is insignificant.
Try using the same code without the BufferedReaders and BufferedWriters, in case there is delay introduced by the buffering. I'm not sure how long buffered writers wait to flush, but at the very least, removing them would help simplify your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With