Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: apps/benchmark/measurements_unittest.cc

Issue 1305193002: Trace-based benchmarking via a mojo app. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Further address Etienne's comments. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « apps/benchmark/measurements.cc ('k') | apps/benchmark/run_args.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "apps/benchmark/measurements.h"
6
7 #include <algorithm>
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace benchmark {
12 namespace {
13
14 base::TimeTicks Ticks(int64 value) {
15 return base::TimeTicks::FromInternalValue(value);
16 }
17
18 base::TimeDelta Delta(int64 value) {
19 return base::TimeDelta::FromInternalValue(value);
20 }
21
22 class MeasurementsTest : public ::testing::Test {
23 protected:
24 void SetUp() override {
25 events_.resize(6);
26 events_[0] = Event("a", "some", Ticks(10), Delta(2));
27 events_[1] = Event("a", "some", Ticks(11), Delta(4));
28 events_[2] = Event("a", "other", Ticks(12), Delta(8));
29 events_[3] = Event("b", "some", Ticks(3), Delta(16));
30 events_[4] = Event("b", "some", Ticks(13), Delta(32));
31 // Event entries carrying metadata have timestamp of 0.
32 events_[5] = Event("something", "__metadata", Ticks(0), Delta(0));
33
34 reversed_ = events_;
35 reverse(reversed_.begin(), reversed_.end());
36 }
37
38 std::vector<Event> events_;
39 std::vector<Event> reversed_;
40 };
41
42 TEST_F(MeasurementsTest, MeasureTimeUntil) {
43 // The results should be the same regardless of the order of events.
44 Measurements regular(events_, base::TimeTicks::FromInternalValue(2));
45 Measurements reversed(reversed_, base::TimeTicks::FromInternalValue(2));
46
47 EXPECT_DOUBLE_EQ(0.008, regular.Measure(Measurement(
48 MeasurementType::TIME_UNTIL, "a", "some")));
49 EXPECT_DOUBLE_EQ(0.008, reversed.Measure(Measurement(
50 MeasurementType::TIME_UNTIL, "a", "some")));
51
52 EXPECT_DOUBLE_EQ(0.01, regular.Measure(Measurement(
53 MeasurementType::TIME_UNTIL, "a", "other")));
54 EXPECT_DOUBLE_EQ(0.01, reversed.Measure(Measurement(
55 MeasurementType::TIME_UNTIL, "a", "other")));
56
57 EXPECT_DOUBLE_EQ(0.001, regular.Measure(Measurement(
58 MeasurementType::TIME_UNTIL, "b", "some")));
59 EXPECT_DOUBLE_EQ(0.001, reversed.Measure(Measurement(
60 MeasurementType::TIME_UNTIL, "b", "some")));
61 }
62
63 TEST_F(MeasurementsTest, MeasureAvgDuration) {
64 // The results should be the same regardless of the order of events.
65 Measurements regular(events_, base::TimeTicks::FromInternalValue(2));
66 Measurements reversed(reversed_, base::TimeTicks::FromInternalValue(2));
67
68 EXPECT_DOUBLE_EQ(0.003, regular.Measure(Measurement(
69 MeasurementType::AVG_DURATION, "a", "some")));
70 EXPECT_DOUBLE_EQ(0.003, reversed.Measure(Measurement(
71 MeasurementType::AVG_DURATION, "a", "some")));
72
73 EXPECT_DOUBLE_EQ(0.008, regular.Measure(Measurement(
74 MeasurementType::AVG_DURATION, "a", "other")));
75 EXPECT_DOUBLE_EQ(0.008, reversed.Measure(Measurement(
76 MeasurementType::AVG_DURATION, "a", "other")));
77
78 EXPECT_DOUBLE_EQ(0.024, regular.Measure(Measurement(
79 MeasurementType::AVG_DURATION, "b", "some")));
80 EXPECT_DOUBLE_EQ(0.024, reversed.Measure(Measurement(
81 MeasurementType::AVG_DURATION, "b", "some")));
82 }
83
84 TEST_F(MeasurementsTest, NoMatchingEvent) {
85 // The results should be the same regardless of the order of events.
86 Measurements empty(std::vector<Event>(),
87 base::TimeTicks::FromInternalValue(0));
88 Measurements regular(events_, base::TimeTicks::FromInternalValue(0));
89 Measurements reversed(reversed_, base::TimeTicks::FromInternalValue(0));
90
91 EXPECT_DOUBLE_EQ(-1.0, empty.Measure(Measurement(
92 MeasurementType::AVG_DURATION, "miss", "cat")));
93 EXPECT_DOUBLE_EQ(-1.0, regular.Measure(Measurement(
94 MeasurementType::AVG_DURATION, "miss", "cat")));
95 EXPECT_DOUBLE_EQ(-1.0, reversed.Measure(Measurement(
96 MeasurementType::AVG_DURATION, "miss", "cat")));
97
98 EXPECT_DOUBLE_EQ(-1.0, empty.Measure(Measurement(MeasurementType::TIME_UNTIL,
99 "miss", "cat")));
100 EXPECT_DOUBLE_EQ(-1.0, regular.Measure(Measurement(
101 MeasurementType::TIME_UNTIL, "miss", "cat")));
102 EXPECT_DOUBLE_EQ(-1.0, reversed.Measure(Measurement(
103 MeasurementType::TIME_UNTIL, "miss", "cat")));
104 }
105
106 } // namespace
107
108 } // namespace benchmark
OLDNEW
« no previous file with comments | « apps/benchmark/measurements.cc ('k') | apps/benchmark/run_args.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698