Update V8 to version 4.7.42.
[chromium-blink-merge.git] / content / common / cc_messages_perftest.cc
blob78085d21f5606a590e7f24970f153cd878f05c04
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.
5 #include "content/common/cc_messages.h"
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"
14 using cc::CompositorFrame;
15 using cc::DelegatedFrameData;
16 using cc::DrawQuad;
17 using cc::PictureDrawQuad;
18 using cc::RenderPass;
19 using cc::SharedQuadState;
21 namespace content {
22 namespace {
24 static const int kTimeLimitMillis = 2000;
25 static const int kNumWarmupRuns = 20;
26 static const int kTimeCheckInterval = 10;
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);
36 base::TimeTicks start = base::TimeTicks::Now();
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;
48 base::TimeTicks now = base::TimeTicks::Now();
49 if (now - start < min_time || min_time == base::TimeDelta())
50 min_time = now - start;
51 start = base::TimeTicks::Now();
54 perf_test::PrintResult(
55 "min_frame_serialization_time",
56 "",
57 test_name,
58 min_time.InMillisecondsF() / kTimeCheckInterval * 1000,
59 "us",
60 true);
64 TEST_F(CCMessagesPerfTest, DelegatedFrame_ManyQuads_1_4000) {
65 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
67 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
68 render_pass->CreateAndAppendSharedQuadState();
69 for (int i = 0; i < 4000; ++i) {
70 PictureDrawQuad* quad =
71 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
72 quad->shared_quad_state = render_pass->shared_quad_state_list.back();
75 frame->delegated_frame_data.reset(new DelegatedFrameData);
76 frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
78 RunTest("DelegatedFrame_ManyQuads_1_4000", *frame);
81 TEST_F(CCMessagesPerfTest, DelegatedFrame_ManyQuads_1_100000) {
82 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
84 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
85 render_pass->CreateAndAppendSharedQuadState();
86 for (int i = 0; i < 100000; ++i) {
87 PictureDrawQuad* quad =
88 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
89 quad->shared_quad_state = render_pass->shared_quad_state_list.back();
92 frame->delegated_frame_data.reset(new DelegatedFrameData);
93 frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
95 RunTest("DelegatedFrame_ManyQuads_1_100000", *frame);
98 TEST_F(CCMessagesPerfTest, DelegatedFrame_ManyQuads_4000_4000) {
99 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
101 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
102 for (int i = 0; i < 4000; ++i) {
103 render_pass->CreateAndAppendSharedQuadState();
104 PictureDrawQuad* quad =
105 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
106 quad->shared_quad_state = render_pass->shared_quad_state_list.back();
109 frame->delegated_frame_data.reset(new DelegatedFrameData);
110 frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
112 RunTest("DelegatedFrame_ManyQuads_4000_4000", *frame);
115 TEST_F(CCMessagesPerfTest, DelegatedFrame_ManyQuads_100000_100000) {
116 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
118 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
119 for (int i = 0; i < 100000; ++i) {
120 render_pass->CreateAndAppendSharedQuadState();
121 PictureDrawQuad* quad =
122 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
123 quad->shared_quad_state = render_pass->shared_quad_state_list.back();
126 frame->delegated_frame_data.reset(new DelegatedFrameData);
127 frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
129 RunTest("DelegatedFrame_ManyQuads_100000_100000", *frame);
132 TEST_F(CCMessagesPerfTest,
133 DelegatedFrame_ManyRenderPasses_10000_100) {
134 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
135 frame->delegated_frame_data.reset(new DelegatedFrameData);
137 for (int i = 0; i < 1000; ++i) {
138 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
139 for (int j = 0; j < 100; ++j) {
140 render_pass->CreateAndAppendSharedQuadState();
141 PictureDrawQuad* quad =
142 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
143 quad->shared_quad_state = render_pass->shared_quad_state_list.back();
145 frame->delegated_frame_data->render_pass_list.push_back(render_pass.Pass());
148 RunTest("DelegatedFrame_ManyRenderPasses_10000_100", *frame);
151 } // namespace
152 } // namespace content