View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  package org.apache.hc.core5.benchmark;
28  
29  import java.io.PrintStream;
30  import java.text.NumberFormat;
31  import java.util.Locale;
32  
33  public class ResultFormatter {
34  
35      private ResultFormatter() {
36          // Do not allow utility class to be instantiated.
37      }
38  
39      static final NumberFormat nf2 = NumberFormat.getInstance(Locale.ROOT);
40      static final NumberFormat nf3 = NumberFormat.getInstance(Locale.ROOT);
41      static final NumberFormat nf6 = NumberFormat.getInstance(Locale.ROOT);
42  
43      static {
44          nf2.setMaximumFractionDigits(2);
45          nf2.setMinimumFractionDigits(2);
46          nf3.setMaximumFractionDigits(3);
47          nf3.setMinimumFractionDigits(3);
48          nf6.setMaximumFractionDigits(6);
49          nf6.setMinimumFractionDigits(6);
50      }
51  
52      public static void print(final PrintStream printStream, final Results results) {
53          printStream.println("Server Software:\t\t" + results.getServerName());
54          printStream.println("Protocol version:\t\t" + results.getProtocolVersion());
55          printStream.println("Server Hostname:\t\t" + results.getHostName());
56          printStream.println("Server Port:\t\t\t" + results.getHostPort());
57          printStream.println("Document Path:\t\t\t" + results.getDocumentPath());
58          printStream.println("Document Length:\t\t" + results.getContentLength() + " bytes\n");
59          printStream.println("Concurrency Level:\t\t" + results.getConcurrencyLevel());
60          printStream.println("Time taken for tests:\t" + nf6.format((double) results.getTotalTimeMillis() / 1000) + " seconds");
61          printStream.println("Complete requests:\t\t" + results.getSuccessCount());
62          printStream.println("Failed requests:\t\t" + results.getFailureCount());
63          printStream.println("Kept alive:\t\t\t\t" + results.getKeepAliveCount());
64          printStream.println("Total transferred:\t\t" + results.getTotalBytesRcvd() + " bytes");
65          printStream.println("Content transferred:\t" + results.getTotalContentBytesRecvd() + " bytes");
66          printStream.println("Requests per second:\t" + nf2.format(
67                  results.getSuccessCount() / ((double) results.getTotalTimeMillis() / 1000)) + " [#/sec] (mean)");
68          printStream.println("Time per request:\t\t" + nf3.format(
69                  (double) results.getTotalTimeMillis() * results.getConcurrencyLevel() / results.getSuccessCount()) + " [ms] (mean)");
70          printStream.println("Time per request:\t\t" + nf3.format(
71                  (double) results.getTotalTimeMillis() / results.getSuccessCount()) + " [ms] (mean, across all concurrent requests)");
72          printStream.println("Transfer rate:\t\t\t" +
73              nf2.format((double) results.getTotalBytesRcvd() / 1024 / ((double) results.getTotalTimeMillis() / 1000)) + " [Kbytes/sec] received");
74      }
75  
76  }