I have a script in Python that does some calculations. When I run this console script, it takes about 7 minutes, but when I run it, the Java shell takes three times longer. I use the following code to execute a 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 idea why the Python script runs Java three times as much as the console?
update (12.29.2010)
The calculation is performed as follows:
- Java sends data to Python.
- Python reads data.
- Python generates a decision tree - this is a lengthy operation.
- Python sends a confirmation that the tree is ready.
- Java receives confirmation.
Later there is a series of messages between Java and Python, but it only takes a few seconds.
update (12.29.2010)
Thanks for your comments and suggestions. It took one business day to find out that my assumption was wrong. The code I used was a “bug”, and in fact, different calculations were done in the console and in the shell. When I fixed this, the calculation time was the same.
Summary: The calculation time of the script is executed in the console and in the Java shell almost the same. The extra time to initialize Java VM and IO messages is negligible.
java python shellexecute
czuk
source share