change benchmark to run once, not up to seven times
[IRC.git] / Robust / src / Benchmarks / SingleTM / add.java
1 import java.io.*;
2 public class add {
3     public static void main(String args[]) {
4       int ii=0;
5       boolean outputerr=false;      
6       boolean normalize=false;
7       boolean timeinsec=false;
8       double norma=0.0;
9       for(;ii<args.length;ii++) {
10         if (args[ii].equals("-err"))
11           outputerr=true;
12         else if (args[ii].equals("-sec")) {
13           timeinsec=true;
14         } else if (args[ii].equals("-norm")) {
15           normalize=true;
16           ii++;
17           norma=Double.parseDouble(args[ii]);
18         } else
19           break;
20       }
21
22       String filename=args[ii];
23
24       try {
25         BufferedReader br=new BufferedReader(new FileReader(filename));
26         double vals[]=new double[1000];
27         int numvals=0;
28         String nextline=null;
29         while((nextline=br.readLine())!=null) {
30           double v;
31           int start=nextline.indexOf("TIME=")+5;
32
33           if (start==4) {
34             start=nextline.indexOf("Time: ")+6;
35             if (start==5) {
36               start=nextline.indexOf("Time = ")+7;
37               if (start==6) {
38                 start=nextline.indexOf("Time taken for kernel 1 is  ")+28;
39                 if (start==27) {
40                   start=nextline.indexOf("Time taken for kernel 1 is ")+27;
41                   if (start==26) {
42                     start=nextline.indexOf("Elapsed time    = ")+18;
43                     if (start==17) {
44                       start=nextline.indexOf("Elapsed time                    = ");
45                       if (start==-1) {
46                         start=nextline.indexOf("Learn time = ");
47                         if (start==-1)
48                           continue;
49                         else
50                           start+=(new String("Learn time = ")).length();
51                       } else {
52                         start+=(new String("Elapsed time                    = ")).length();
53                       }
54                     }
55                   }
56                 }
57               }
58             }
59           }
60           
61           nextline=nextline.substring(start, nextline.length());
62           int lastindex=nextline.indexOf(' ');
63           if (lastindex==-1)
64             lastindex=nextline.length();
65           String num=nextline.substring(0, lastindex);
66           v=Double.parseDouble(num);
67           if (timeinsec)
68             v=v*1000;
69
70           if (normalize)
71             v=norma/v;
72           vals[numvals++]=v;
73         }
74         double sum=0;
75         for(int i=0;i<numvals;i++) {
76           sum+=vals[i];
77         }
78         double ave=((double)sum)/numvals;
79         double diff=0;
80         for(int i=0;i<numvals;i++) {
81           double delta=vals[i]-ave;
82           diff+=delta*delta;
83         }
84         diff=diff/(numvals-1);
85         double std=Math.sqrt(diff);
86         double err=std/Math.sqrt(numvals);
87         if (!outputerr)
88           System.out.println(ave);
89         else
90           System.out.println(err);
91       } catch (Exception e) {
92         e.printStackTrace();
93       }
94     }
95 }