Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/eireneh/bible/view/cli/Bench.java


1   
2   package com.eireneh.bible.view.cli;
3   
4   import java.io.*;
5   
6   import com.eireneh.util.*;
7   import com.eireneh.util.event.*;
8   import com.eireneh.bible.util.Project;
9   import com.eireneh.bible.control.test.Speed;
10  import com.eireneh.bible.book.*;
11  import com.eireneh.bible.book.raw.RawBibleDriver;
12  
13  /**
14   * Bench is a command line utility that the Speed benchmark program.
15   *
16   * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
17   * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
18   * Distribution Licence:<br />
19   * Project B is free software; you can redistribute it
20   * and/or modify it under the terms of the GNU General Public License,
21   * version 2 as published by the Free Software Foundation.<br />
22   * This program is distributed in the hope that it will be useful,
23   * but WITHOUT ANY WARRANTY; without even the implied warranty of
24   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25   * General Public License for more details.<br />
26   * The License is available on the internet
27   * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
28   * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29   * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
30   * The copyright to this program is held by it's authors.
31   * </font></td></tr></table>
32   * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
33   * @see docs.Licence
34   * @author Joe Walker
35   * @version D0.I0.T0
36   */
37  public class Bench
38  {
39      /**
40       * Basic constructor
41       */
42      public static void main(String[] args)
43      {
44          Project.init();
45          StdOutCaptureListener.setHelpDeskInformListener(true);
46          StdOutCaptureListener.setHelpDeskLogListener(true);
47  
48          Bible version = null;
49  
50          if (args.length == 0)
51          {
52              usage();
53              versions();
54              System.exit(1);
55          }
56  
57          if (args.length > 1 && args[1].equals("disk"))
58              RawBibleDriver.setDefaultCacheData(false);
59  
60          try
61          {
62              version = Bibles.getBible(args[0]);
63          }
64          catch (Exception ex)
65          {
66              Reporter.informUser(Bench.class, ex);
67  
68              System.out.println("Failed to load version '"+args[0]+"'");
69              System.out.println("System message: "+ex);
70              System.out.println("");
71              usage();
72              System.exit(1);
73          }
74  
75          Speed speed = new Speed(version);
76          speed.run();
77  
78          try
79          {
80              float time = speed.getBenchmark() / 1000;
81              System.out.println("CBench mark for '"+args[0]+"': "+time+"s");
82          }
83          catch (Exception ex)
84          {
85              System.out.println("Benchmark failed. No timing available.");
86          }
87      }
88  
89      /**
90       * Print a usage message to stdout
91       */
92      private static void usage()
93      {
94          System.out.println("Usage: CBench [<version>] [disk]");
95          System.out.println("  where <version> is the name of a version to benchmark.");
96          System.out.println("  and 'disk' specifies if the Raw version should not cache data.");
97          System.out.println("  Remember to quote the version name if it includes spaces.");
98      }
99  
100     /**
101      * List the available versions
102      */
103     private static void versions()
104     {
105         try
106         {
107             String[] names = Bibles.getBibleNames();
108             System.out.println("  Available versions:");
109             for (int i=0; i<names.length; i++)
110             {
111                 System.out.println("    "+names[i]);
112             }
113         }
114         catch (BookException ex)
115         {
116             System.out.println("  Can't list versions. System message: "+ex);
117         }
118     }
119 }