01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2005 Robert Grimm
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.util;
20:
21: import java.io.BufferedReader;
22: import java.io.FileReader;
23:
24: /**
25: * A small utility program to compute a tool's throughput. This
26: * program takes as its input a text file, which contains one or more
27: * <file size in bytes, latency in seconds> pairs. Each pair is
28: * specified on its own line, with the first number being a long
29: * number, the second number being a double number, and the two
30: * numbers being separated by a single space.
31: *
32: * @author Robert Grimm
33: * @version $Revision: 1.4 $
34: */
35: public class Throughput {
36:
37: /** Compute the throughput for the file specified on the command line. */
38: public static void main(String[] args) {
39: try {
40: Statistics sizes = new Statistics();
41: Statistics latencies = new Statistics();
42: BufferedReader in = new BufferedReader(new FileReader(
43: args[0]));
44:
45: for (String line = in.readLine(); null != line; line = in
46: .readLine()) {
47: int idx = line.indexOf(' ');
48: long size = Long.parseLong(line.substring(0, idx));
49: double latency = Double.parseDouble(line
50: .substring(idx + 1));
51:
52: sizes.add(size / 1024.0);
53: latencies.add(latency);
54: }
55:
56: double throughput = 1.0 / Statistics.fitSlope(sizes,
57: latencies);
58:
59: System.out.println("Overall performance : "
60: + Statistics.round(throughput) + " KB/s");
61: } catch (Exception x) {
62: System.exit(1);
63: }
64: System.exit(0);
65: }
66:
67: }
|