/src/mozilla-central/layout/style/test/gtest/StyloParsingBench.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "gtest/gtest.h" |
8 | | #include "gtest/MozGTestBench.h" |
9 | | #include "nsString.h" |
10 | | #include "ExampleStylesheet.h" |
11 | | #include "ServoBindings.h" |
12 | | #include "mozilla/Encoding.h" |
13 | | #include "mozilla/NullPrincipalURI.h" |
14 | | #include "mozilla/net/ReferrerPolicy.h" |
15 | | |
16 | | using namespace mozilla; |
17 | | using namespace mozilla::css; |
18 | | using namespace mozilla::dom; |
19 | | using namespace mozilla::net; |
20 | | |
21 | | // Bug 1436018 - Disable Stylo microbenchmark on Windows |
22 | | #if !defined(_WIN32) && !defined(_WIN64) |
23 | | |
24 | 0 | #define PARSING_REPETITIONS 20 |
25 | 0 | #define SETPROPERTY_REPETITIONS (1000 * 1000) |
26 | 0 | #define GETPROPERTY_REPETITIONS (1000 * 1000) |
27 | | |
28 | | static void ServoParsingBench(const StyleUseCounters* aCounters) |
29 | 0 | { |
30 | 0 | auto css = AsBytes(MakeStringSpan(EXAMPLE_STYLESHEET)); |
31 | 0 | nsCString cssStr; |
32 | 0 | cssStr.Append(css); |
33 | 0 | ASSERT_EQ(Encoding::UTF8ValidUpTo(css), css.Length()); |
34 | 0 |
|
35 | 0 | RefPtr<URLExtraData> data = |
36 | 0 | new URLExtraData(NullPrincipalURI::Create(), |
37 | 0 | nullptr, |
38 | 0 | NullPrincipal::CreateWithoutOriginAttributes(), |
39 | 0 | mozilla::net::RP_Unset); |
40 | 0 | for (int i = 0; i < PARSING_REPETITIONS; i++) { |
41 | 0 | RefPtr<RawServoStyleSheetContents> stylesheet = |
42 | 0 | Servo_StyleSheet_FromUTF8Bytes(nullptr, |
43 | 0 | nullptr, |
44 | 0 | nullptr, |
45 | 0 | &cssStr, |
46 | 0 | eAuthorSheetFeatures, |
47 | 0 | data, |
48 | 0 | 0, |
49 | 0 | eCompatibility_FullStandards, |
50 | 0 | nullptr, |
51 | 0 | aCounters) |
52 | 0 | .Consume(); |
53 | 0 | } |
54 | 0 | } |
55 | | |
56 | | static void ServoSetPropertyByIdBench(const nsACString& css) |
57 | 0 | { |
58 | 0 | RefPtr<RawServoDeclarationBlock> block = Servo_DeclarationBlock_CreateEmpty().Consume(); |
59 | 0 | RefPtr<URLExtraData> data = |
60 | 0 | new URLExtraData(NullPrincipalURI::Create(), |
61 | 0 | nullptr, |
62 | 0 | NullPrincipal::CreateWithoutOriginAttributes(), |
63 | 0 | mozilla::net::RP_Unset); |
64 | 0 | ASSERT_TRUE(IsUTF8(css)); |
65 | 0 |
|
66 | 0 | for (int i = 0; i < SETPROPERTY_REPETITIONS; i++) { |
67 | 0 | Servo_DeclarationBlock_SetPropertyById( |
68 | 0 | block, |
69 | 0 | eCSSProperty_width, |
70 | 0 | &css, |
71 | 0 | /* is_important = */ false, |
72 | 0 | data, |
73 | 0 | ParsingMode::Default, |
74 | 0 | eCompatibility_FullStandards, |
75 | 0 | nullptr, |
76 | 0 | { } |
77 | 0 | ); |
78 | 0 | } |
79 | 0 | } |
80 | | |
81 | 0 | static void ServoGetPropertyValueById() { |
82 | 0 | RefPtr<RawServoDeclarationBlock> block = Servo_DeclarationBlock_CreateEmpty().Consume(); |
83 | 0 | RefPtr<URLExtraData> data = |
84 | 0 | new URLExtraData(NullPrincipalURI::Create(), |
85 | 0 | nullptr, |
86 | 0 | NullPrincipal::CreateWithoutOriginAttributes(), |
87 | 0 | mozilla::net::RP_Unset); |
88 | 0 | NS_NAMED_LITERAL_CSTRING(css_, "10px"); |
89 | 0 | const nsACString& css = css_; |
90 | 0 | Servo_DeclarationBlock_SetPropertyById( |
91 | 0 | block, |
92 | 0 | eCSSProperty_width, |
93 | 0 | &css, |
94 | 0 | /* is_important = */ false, |
95 | 0 | data, |
96 | 0 | ParsingMode::Default, |
97 | 0 | eCompatibility_FullStandards, |
98 | 0 | nullptr, |
99 | 0 | { } |
100 | 0 | ); |
101 | 0 |
|
102 | 0 | for (int i = 0; i < GETPROPERTY_REPETITIONS; i++) { |
103 | 0 | DOMString value_; |
104 | 0 | nsAString& value = value_; |
105 | 0 | Servo_DeclarationBlock_GetPropertyValueById( |
106 | 0 | block, |
107 | 0 | eCSSProperty_width, |
108 | 0 | &value |
109 | 0 | ); |
110 | 0 | ASSERT_TRUE(value.EqualsLiteral("10px")); |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | | MOZ_GTEST_BENCH(Stylo, Servo_StyleSheet_FromUTF8Bytes_Bench, [] { |
115 | | ServoParsingBench(nullptr); |
116 | | }); |
117 | | |
118 | | MOZ_GTEST_BENCH(Stylo, Servo_StyleSheet_FromUTF8Bytes_Bench_UseCounters, [] { |
119 | | UniquePtr<StyleUseCounters> counters(Servo_UseCounters_Create()); |
120 | | ServoParsingBench(counters.get()); |
121 | | }); |
122 | | |
123 | | MOZ_GTEST_BENCH(Stylo, Servo_DeclarationBlock_SetPropertyById_Bench, [] { |
124 | | ServoSetPropertyByIdBench(NS_LITERAL_CSTRING("10px")); |
125 | | }); |
126 | | |
127 | | MOZ_GTEST_BENCH(Stylo, Servo_DeclarationBlock_SetPropertyById_WithInitialSpace_Bench, [] { |
128 | | ServoSetPropertyByIdBench(NS_LITERAL_CSTRING(" 10px")); |
129 | | }); |
130 | | |
131 | | MOZ_GTEST_BENCH(Stylo, Servo_DeclarationBlock_GetPropertyById_Bench, ServoGetPropertyValueById); |
132 | | |
133 | | #endif |