summaryrefslogtreecommitdiff
path: root/chromium/ui/views/controls/label_perftest.cc
blob: bd0094dfb6a3648d8c6a17cc85b1c31fa84782c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/views/controls/label.h"

#include "base/strings/utf_string_conversions.h"
#include "cc/base/lap_timer.h"
#include "testing/perf/perf_test.h"
#include "ui/views/test/views_test_base.h"

namespace views {

using LabelPerfTest = ViewsTestBase;

// Test the number of text size measurements that can be made made per second.
// This should surface any performance regressions in underlying text layout
// system, e.g., failure to cache font structures.
TEST_F(LabelPerfTest, GetPreferredSize) {
  Label label;

  // Alternate between two strings to ensure caches are cleared.
  base::string16 string1 = base::ASCIIToUTF16("boring ascii string");
  base::string16 string2 = base::ASCIIToUTF16("another uninteresting sequence");

  constexpr int kLaps = 5000;  // Aim to run in under 3 seconds.
  constexpr int kWarmupLaps = 5;

  // The time limit is unused. Use kLaps for the check interval so the time is
  // only measured once.
  cc::LapTimer timer(kWarmupLaps, base::TimeDelta(), kLaps);
  for (int i = 0; i < kLaps + kWarmupLaps; ++i) {
    label.SetText(i % 2 == 0 ? string1 : string2);
    label.GetPreferredSize();
    timer.NextLap();
  }
  perf_test::PrintResult("LabelPerfTest", std::string(), "GetPreferredSize",
                         timer.LapsPerSecond(), "runs/s", true);
}

}  // namespace views