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

Side by Side Diff: cc/base/rtree_perftest.cc

Issue 2576793002: cc: Add rtree perftests. (Closed)
Patch Set: rtreefix: remove_unittest Created 4 years 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 | « cc/base/DEPS ('k') | no next file » | 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 2016 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 "cc/base/rtree.h"
6 #include "cc/debug/lap_timer.h"
7
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/perf/perf_test.h"
10
11 namespace cc {
12 namespace {
13
14 static const int kTimeLimitMillis = 2000;
15 static const int kWarmupRuns = 5;
16 static const int kTimeCheckInterval = 10;
17
18 class RTreePerfTest : public testing::Test {
19 public:
20 RTreePerfTest()
21 : timer_(kWarmupRuns,
22 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
23 kTimeCheckInterval) {}
24
25 void RunConstructTest(const std::string& test_name, int rect_count) {
26 std::vector<gfx::Rect> rects = BuildRects(rect_count);
27 timer_.Reset();
28 do {
29 RTree rtree;
30 rtree.Build(rects);
31 timer_.NextLap();
32 } while (!timer_.HasTimeLimitExpired());
33
34 perf_test::PrintResult("rtree_construct", "", test_name,
35 timer_.LapsPerSecond(), "runs/s", true);
36 }
37
38 void RunSearchTest(const std::string& test_name, int rect_count) {
39 std::vector<gfx::Rect> queries = {
40 gfx::Rect(0, 0, 1, 1), gfx::Rect(100, 100, 2, 2),
41 gfx::Rect(-10, -10, 1, 1), gfx::Rect(0, 0, 1000, 1000)};
danakj 2016/12/14 20:36:44 Maybe consider a query on the bottom/right for lar
vmpstr 2016/12/14 20:43:13 Done.
42 size_t query_index = 0;
43
44 std::vector<gfx::Rect> rects = BuildRects(rect_count);
45 RTree rtree;
46 rtree.Build(rects);
47
48 timer_.Reset();
49 do {
50 std::vector<size_t> results;
51 rtree.Search(queries[query_index], &results);
52 query_index = (query_index + 1) % queries.size();
53 timer_.NextLap();
54 } while (!timer_.HasTimeLimitExpired());
55
56 perf_test::PrintResult("rtree_search", "", test_name,
57 timer_.LapsPerSecond(), "runs/s", true);
58 }
59
60 std::vector<gfx::Rect> BuildRects(int count) {
61 std::vector<gfx::Rect> result;
62 int width = std::sqrt(count);
63 int x = 0;
64 int y = 0;
65 for (int i = 0; i < count; ++i) {
66 result.push_back(gfx::Rect(x, y, 1, 1));
67 if (++x > width) {
68 x = 0;
69 ++y;
70 }
71 }
72 return result;
73 }
74
75 protected:
76 LapTimer timer_;
77 };
78
79 TEST_F(RTreePerfTest, Construct) {
80 RunConstructTest("100", 100);
81 RunConstructTest("1000", 1000);
82 RunConstructTest("10000", 10000);
83 RunConstructTest("100000", 100000);
84 }
85
86 TEST_F(RTreePerfTest, Search) {
87 RunSearchTest("100", 100);
88 RunSearchTest("1000", 1000);
89 RunSearchTest("10000", 10000);
90 RunSearchTest("100000", 100000);
91 }
92
93 } // namespace
94 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698