Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- //Program pokrece proces i uzima output,i meri vreme sa odsupanjem 30-50ms zbog samih java funkcija koje se u mredju vremenu pokrecu da bi uzele output
- public class tes {
- public static void main(String args[]) {
- try {
- String line;
- long start = System.nanoTime();
- /*sam gasi proces ako je proces previse dug npr 15 000ms*/
- /*test 7, broji do 50, sa medju uspavljivanjem od 25ms*/
- /*test.exe samo ispisuje radi*/
- /*test5.exe samo uspavljuje nit za 5000ms, preko njega moze da se izmeri i maksimalno smanji odstupanje tako sto bi se u krajnjem vremenu oduzela prosecna vrednost odstupanja*/
- Process p = Runtime.getRuntime().exec("\"c:/test7.exe\"");
- BufferedReader bri = new BufferedReader
- (new InputStreamReader(p.getInputStream()));
- BufferedReader bre = new BufferedReader
- (new InputStreamReader(p.getErrorStream()));
- while ((line = bri.readLine()) != null) {
- System.out.println(line);
- }
- bri.close();
- while ((line = bre.readLine()) != null) {
- System.out.println(line);
- }
- bre.close();
- p.waitFor();
- long end = System.nanoTime();long elapsedTime = end - start;
- System.out.println("Vreme : " + elapsedTime* 1.0e-6 + "ms");
- }
- catch (Exception err) {
- err.printStackTrace();
- }
- }
- }
- /* long start = System.nanoTime();
- System.out.println("Start: " + start);
- //
- // Just do some a bit long process calculating the total value
- // of even number from zero to 10000
- //
- int totalEven = 0;
- for (int i = 0; i < 10000; i++) {
- if (i % 2 == 0) {
- totalEven = totalEven + i;
- }
- }
- // Get the end time of the process
- long end = System.nanoTime();
- System.out.println("End : " + end);
- long elapsedTime = end - start;*/
Add Comment
Please, Sign In to add comment