Bug 1394792 - Add gtest microbenchmark for Servo_DeclarationBlock_GetPropertyValueById. r?emilio draft
authorSimon Sapin <simon.sapin@exyr.org>
Tue, 29 Aug 2017 15:27:46 +0200
changeset 654962 be7f75fdf8cfaf31cfb921e09be10cab04aa3ac9
parent 654592 1b4c59eef820b46eb0037aca68f83a15088db45f
child 728709 31f69d8ae584133d6d3fa0b82732ac9bce832ef3
push id76733
push userbmo:simon.sapin@exyr.org
push dateTue, 29 Aug 2017 13:38:46 +0000
reviewersemilio
bugs1394792
milestone57.0a1
Bug 1394792 - Add gtest microbenchmark for Servo_DeclarationBlock_GetPropertyValueById. r?emilio MozReview-Commit-ID: 68RkTgnzdZj
layout/style/test/gtest/StyloParsingBench.cpp
--- a/layout/style/test/gtest/StyloParsingBench.cpp
+++ b/layout/style/test/gtest/StyloParsingBench.cpp
@@ -8,20 +8,22 @@
 #include "nsString.h"
 #include "ExampleStylesheet.h"
 #include "ServoBindings.h"
 #include "NullPrincipalURI.h"
 #include "nsCSSParser.h"
 
 using namespace mozilla;
 using namespace mozilla::css;
+using namespace mozilla::dom;
 using namespace mozilla::net;
 
 #define PARSING_REPETITIONS 20
 #define SETPROPERTY_REPETITIONS (1000 * 1000)
+#define GETPROPERTY_REPETITIONS (1000 * 1000)
 
 #ifdef MOZ_STYLO
 
 static void ServoParsingBench() {
   NS_NAMED_LITERAL_CSTRING(css_, EXAMPLE_STYLESHEET);
   const nsACString& css = css_;
   ASSERT_TRUE(IsUTF8(css));
 
@@ -86,9 +88,41 @@ static void ServoSetPropertyByIdBench(co
 MOZ_GTEST_BENCH(Stylo, Servo_DeclarationBlock_SetPropertyById_Bench, [] {
   ServoSetPropertyByIdBench(NS_LITERAL_CSTRING("10px"));
 });
 
 MOZ_GTEST_BENCH(Stylo, Servo_DeclarationBlock_SetPropertyById_WithInitialSpace_Bench, [] {
   ServoSetPropertyByIdBench(NS_LITERAL_CSTRING(" 10px"));
 });
 
+static void ServoGetPropertyValueById() {
+  RefPtr<RawServoDeclarationBlock> block = Servo_DeclarationBlock_CreateEmpty().Consume();
+  RefPtr<URLExtraData> data = new URLExtraData(
+    NullPrincipalURI::Create(), nullptr, NullPrincipal::Create());
+  NS_NAMED_LITERAL_CSTRING(css_, "10px");
+  const nsACString& css = css_;
+  Servo_DeclarationBlock_SetPropertyById(
+    block,
+    eCSSProperty_width,
+    &css,
+    /* is_important = */ false,
+    data,
+    ParsingMode::Default,
+    eCompatibility_FullStandards,
+    nullptr
+  );
+
+  for (int i = 0; i < GETPROPERTY_REPETITIONS; i++) {
+    DOMString value_;
+    nsAString& value = value_;
+    Servo_DeclarationBlock_GetPropertyValueById(
+      block,
+      eCSSProperty_width,
+      &value
+    );
+    ASSERT_TRUE(value.EqualsLiteral("10px"));
+  }
+}
+
+MOZ_GTEST_BENCH(Stylo, Servo_DeclarationBlock_GetPropertyById_Bench, ServoGetPropertyValueById);
+
+
 #endif