Bug 1344131 - Add a gtest bench for Servo_DeclarationBlock_SetPropertyById. r=emilio draft
authorSimon Sapin <simon.sapin@exyr.org>
Tue, 18 Jul 2017 08:58:11 +0200
changeset 610597 d899296b63a2e3bf78b65aaea532919ddc67af8e
parent 610234 5e73b9798464c3f7106f0161dc9a49b234f42f9c
child 637914 0f12e4bd66602a200e734da8efbc893b91d36d68
push id68952
push userbmo:simon.sapin@exyr.org
push dateTue, 18 Jul 2017 14:53:21 +0000
reviewersemilio
bugs1344131
milestone56.0a1
Bug 1344131 - Add a gtest bench for Servo_DeclarationBlock_SetPropertyById. r=emilio MozReview-Commit-ID: 83Ryi6CKTLV
layout/style/test/gtest/StyloParsingBench.cpp
--- a/layout/style/test/gtest/StyloParsingBench.cpp
+++ b/layout/style/test/gtest/StyloParsingBench.cpp
@@ -11,16 +11,17 @@
 #include "NullPrincipalURI.h"
 #include "nsCSSParser.h"
 
 using namespace mozilla;
 using namespace mozilla::css;
 using namespace mozilla::net;
 
 #define PARSING_REPETITIONS 20
+#define SETPROPERTY_REPETITIONS (1000 * 1000)
 
 #ifdef MOZ_STYLO
 
 static void ServoParsingBench() {
   NS_NAMED_LITERAL_CSTRING(css_, EXAMPLE_STYLESHEET);
   const nsACString& css = css_;
   ASSERT_TRUE(IsUTF8(css));
 
@@ -52,8 +53,38 @@ static void GeckoParsingBench() {
       eAuthorSheetFeatures, CORS_NONE, RP_No_Referrer);
     stylesheet->SetURIs(uri, uri, uri);
     stylesheet->SetComplete();
     ASSERT_EQ(stylesheet->ReparseSheet(css), NS_OK);
   }
 }
 
 MOZ_GTEST_BENCH(Stylo, Gecko_nsCSSParser_ParseSheet_Bench, GeckoParsingBench);
+
+
+#ifdef MOZ_STYLO
+
+static void ServoSetPropertyByIdBench() {
+  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_;
+  ASSERT_TRUE(IsUTF8(css));
+
+  for (int i = 0; i < SETPROPERTY_REPETITIONS; i++) {
+    Servo_DeclarationBlock_SetPropertyById(
+      block,
+      eCSSProperty_width,
+      &css,
+      /* is_important = */ false,
+      data,
+      ParsingMode::Default,
+      eCompatibility_FullStandards,
+      nullptr
+    );
+  }
+}
+
+MOZ_GTEST_BENCH(Stylo, Servo_DeclarationBlock_SetPropertyById_Bench, ServoSetPropertyByIdBench);
+
+#endif