blob: 00f9350a05fe9a964d0a78a82f6f1c608711dfd4 [file] [log] [blame]
Paul Duffin7fc0b452015-11-10 17:45:15 +00001/**
2 * Copyright (C) 2009 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.caliper;
18
19import com.google.common.annotations.GwtCompatible;
20
21import java.io.Serializable;
22import java.util.Date;
23import java.util.LinkedHashMap;
24import java.util.Map;
25
26/**
27 * The complete result of a benchmark suite run.
28 *
29 * WARNING: a JSON representation of this class is stored on the app engine server. If any changes
30 * are made to this class, a deserialization adapter must be written for this class to ensure
31 * backwards compatibility.
32 *
33 * <p>Gwt-safe.
34 */
35@SuppressWarnings("serial")
36@GwtCompatible
37public final class Run
38 implements Serializable /* for GWT Serialization */ {
39
40 private /*final*/ Map<Scenario, ScenarioResult> measurements;
41 private /*final*/ String benchmarkName;
42 private /*final*/ long executedTimestamp;
43
44 // TODO: add more run properties such as checksums of the executed code
45
46 public Run(Map<Scenario, ScenarioResult> measurements,
47 String benchmarkName, Date executedTimestamp) {
48 if (benchmarkName == null || executedTimestamp == null) {
49 throw new NullPointerException();
50 }
51
52 this.measurements = new LinkedHashMap<Scenario, ScenarioResult>(measurements);
53 this.benchmarkName = benchmarkName;
54 this.executedTimestamp = executedTimestamp.getTime();
55 }
56
57 public Map<Scenario, ScenarioResult> getMeasurements() {
58 return measurements;
59 }
60
61 public String getBenchmarkName() {
62 return benchmarkName;
63 }
64
65 public Date getExecutedTimestamp() {
66 return new Date(executedTimestamp);
67 }
68
69 @Override public boolean equals(Object o) {
70 if (o instanceof Run) {
71 Run that = (Run) o;
72 return measurements.equals(that.measurements)
73 && benchmarkName.equals(that.benchmarkName)
74 && executedTimestamp == that.executedTimestamp;
75 }
76
77 return false;
78 }
79
80 @Override public int hashCode() {
81 int result = measurements.hashCode();
82 result = result * 37 + benchmarkName.hashCode();
83 result = result * 37 + (int) ((executedTimestamp >> 32) ^ executedTimestamp);
84 return result;
85 }
86
87 @Override public String toString() {
88 return measurements.toString();
89 }
90
91 @SuppressWarnings("unused")
92 private Run() {} // for GWT Serialization
93}