Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / common / cc_messages_perftest.cc
1 // Copyright 2013 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 "content/common/cc_messages.h"
6
7 #include "base/test/launcher/unit_test_launcher.h"
8 #include "base/test/test_suite.h"
9 #include "cc/output/compositor_frame.h"
10 #include "ipc/ipc_message.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/perf/perf_test.h"
13
14 using cc::CompositorFrame;
15 using cc::DelegatedFrameData;
16 using cc::DrawQuad;
17 using cc::PictureDrawQuad;
18 using cc::RenderPass;
19 using cc::SharedQuadState;
20
21 namespace content {
22 namespace {
23
24 static const int kTimeLimitMillis = 2000;
25 static const int kNumWarmupRuns = 20;
26 static const int kTimeCheckInterval = 10;
27
28 class CCMessagesPerfTest : public testing::Test {
29  protected:
30   static void RunTest(std::string test_name, const CompositorFrame& frame) {
31     for (int i = 0; i < kNumWarmupRuns; ++i) {
32       IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
33       IPC::ParamTraits<CompositorFrame>::Write(&msg, frame);
34     }
35
36     base::TimeTicks start = base::TimeTicks::HighResNow();
37     base::TimeTicks end =
38         start + base::TimeDelta::FromMilliseconds(kTimeLimitMillis);
39     base::TimeDelta min_time;
40     int count = 0;
41     while (start < end) {
42       for (int i = 0; i < kTimeCheckInterval; ++i) {
43         IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
44         IPC::ParamTraits<CompositorFrame>::Write(&msg, frame);
45         ++count;
46       }
47
48       base::TimeTicks now = base::TimeTicks::HighResNow();
49       if (now - start < min_time || min_time == base::TimeDelta())
50         min_time = now - start;
51       start = base::TimeTicks::HighResNow();
52     }
53
54     perf_test::PrintResult(
55         "min_frame_serialization_time",
56         "",
57         test_name,
58         min_time.InMillisecondsF() / kTimeCheckInterval * 1000,
59         "us",
60         true);
61   }
62 };
63
64 TEST_F(CCMessagesPerfTest, DelegatedFrame_ManyQuads_1_4000) {
65   scoped_ptr<CompositorFrame> frame(new CompositorFrame);
66
67   scoped_ptr<RenderPass> render_pass = RenderPass::Create();
68   render_pass->CreateAndAppendSharedQuadState();
69   for (int i = 0; i < 4000; ++i) {
70     render_pass->quad_list.push_back(
71         PictureDrawQuad::Create().PassAs<DrawQuad>());
72     render_pass->quad_list.back()->shared_quad_state =
73         render_pass->shared_quad_state_list.back();
74   }
75
76   frame->delegated_frame_data.reset(new DelegatedFrameData);
77   frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
78
79   RunTest("DelegatedFrame_ManyQuads_1_4000", *frame);
80 }
81
82 TEST_F(CCMessagesPerfTest, DelegatedFrame_ManyQuads_1_100000) {
83   scoped_ptr<CompositorFrame> frame(new CompositorFrame);
84
85   scoped_ptr<RenderPass> render_pass = RenderPass::Create();
86   render_pass->CreateAndAppendSharedQuadState();
87   for (int i = 0; i < 100000; ++i) {
88     render_pass->quad_list.push_back(
89         PictureDrawQuad::Create().PassAs<DrawQuad>());
90     render_pass->quad_list.back()->shared_quad_state =
91         render_pass->shared_quad_state_list.back();
92   }
93
94   frame->delegated_frame_data.reset(new DelegatedFrameData);
95   frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
96
97   RunTest("DelegatedFrame_ManyQuads_1_100000", *frame);
98 }
99
100 TEST_F(CCMessagesPerfTest, DelegatedFrame_ManyQuads_4000_4000) {
101   scoped_ptr<CompositorFrame> frame(new CompositorFrame);
102
103   scoped_ptr<RenderPass> render_pass = RenderPass::Create();
104   for (int i = 0; i < 4000; ++i) {
105     render_pass->CreateAndAppendSharedQuadState();
106     render_pass->quad_list.push_back(
107         PictureDrawQuad::Create().PassAs<DrawQuad>());
108     render_pass->quad_list.back()->shared_quad_state =
109         render_pass->shared_quad_state_list.back();
110   }
111
112   frame->delegated_frame_data.reset(new DelegatedFrameData);
113   frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
114
115   RunTest("DelegatedFrame_ManyQuads_4000_4000", *frame);
116 }
117
118 TEST_F(CCMessagesPerfTest, DelegatedFrame_ManyQuads_100000_100000) {
119   scoped_ptr<CompositorFrame> frame(new CompositorFrame);
120
121   scoped_ptr<RenderPass> render_pass = RenderPass::Create();
122   for (int i = 0; i < 100000; ++i) {
123     render_pass->CreateAndAppendSharedQuadState();
124     render_pass->quad_list.push_back(
125         PictureDrawQuad::Create().PassAs<DrawQuad>());
126     render_pass->quad_list.back()->shared_quad_state =
127         render_pass->shared_quad_state_list.back();
128   }
129
130   frame->delegated_frame_data.reset(new DelegatedFrameData);
131   frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
132
133   RunTest("DelegatedFrame_ManyQuads_100000_100000", *frame);
134 }
135
136 TEST_F(CCMessagesPerfTest,
137        DelegatedFrame_ManyRenderPasses_10000_100) {
138   scoped_ptr<CompositorFrame> frame(new CompositorFrame);
139   frame->delegated_frame_data.reset(new DelegatedFrameData);
140
141   for (int i = 0; i < 1000; ++i) {
142     scoped_ptr<RenderPass> render_pass = RenderPass::Create();
143     for (int j = 0; j < 100; ++j) {
144       render_pass->CreateAndAppendSharedQuadState();
145       render_pass->quad_list.push_back(
146           PictureDrawQuad::Create().PassAs<DrawQuad>());
147       render_pass->quad_list.back()->shared_quad_state =
148           render_pass->shared_quad_state_list.back();
149     }
150     frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
151   }
152
153   RunTest("DelegatedFrame_ManyRenderPasses_10000_100", *frame);
154 }
155
156 }  // namespace
157 }  // namespace content