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

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

Issue 2576793002: cc: Add rtree perftests. (Closed)
Patch Set: rtreefix: large_query 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 int large_query = std::sqrt(rect_count);
40
41 std::vector<gfx::Rect> queries = {
42 gfx::Rect(0, 0, 1, 1), gfx::Rect(100, 100, 2, 2),
43 gfx::Rect(-10, -10, 1, 1), gfx::Rect(0, 0, 1000, 1000),
44 gfx::Rect(large_query - 2, large_query - 2, 1, 1)};
45 size_t query_index = 0;
46
47 std::vector<gfx::Rect> rects = BuildRects(rect_count);
48 RTree rtree;
49 rtree.Build(rects);
50
51 timer_.Reset();
52 do {
53 std::vector<size_t> results;
54 rtree.Search(queries[query_index], &results);
55 query_index = (query_index + 1) % queries.size();
56 timer_.NextLap();
57 } while (!timer_.HasTimeLimitExpired());
58
59 perf_test::PrintResult("rtree_search", "", test_name,
60 timer_.LapsPerSecond(), "runs/s", true);
61 }
62
63 std::vector<gfx::Rect> BuildRects(int count) {
64 std::vector<gfx::Rect> result;
65 int width = std::sqrt(count);
66 int x = 0;
67 int y = 0;
68 for (int i = 0; i < count; ++i) {
69 result.push_back(gfx::Rect(x, y, 1, 1));
70 if (++x > width) {
71 x = 0;
72 ++y;
73 }
74 }
75 return result;
76 }
77
78 protected:
79 LapTimer timer_;
80 };
81
82 TEST_F(RTreePerfTest, Construct) {
83 RunConstructTest("100", 100);
84 RunConstructTest("1000", 1000);
85 RunConstructTest("10000", 10000);
86 RunConstructTest("100000", 100000);
87 }
88
89 TEST_F(RTreePerfTest, Search) {
90 RunSearchTest("100", 100);
91 RunSearchTest("1000", 1000);
92 RunSearchTest("10000", 10000);
93 RunSearchTest("100000", 100000);
94 }
95
96 } // namespace
97 } // 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