瀏覽代碼

Add incremental benchmark

Michael Ragazzon 4 月之前
父節點
當前提交
c424be048e
共有 1 個文件被更改,包括 39 次插入14 次删除
  1. 39 14
      Tests/Source/Benchmarks/FontTextureAtlas.cpp

+ 39 - 14
Tests/Source/Benchmarks/FontTextureAtlas.cpp

@@ -38,16 +38,26 @@ TEST_CASE("font_texture_atlas")
 	LoadFontFace("assets/NotoSansJP-Regular.ttf");
 	LoadFontFace("assets/NotoSansJP-Regular.ttf");
 
 
 	nanobench::Bench bench;
 	nanobench::Bench bench;
-	bench.title("Font texture atlas");
+	bool incremental = false;
+	SUBCASE("all at once")
+	{
+		incremental = false;
+		bench.title("Font texture atlas (all at once)");
+	}
+	SUBCASE("incremental")
+	{
+		incremental = true;
+		bench.title("Font texture atlas (incremental)");
+	}
 	bench.relative(true);
 	bench.relative(true);
 
 
 	for (const int font_size : {12, 16, 24, 48, 96})
 	for (const int font_size : {12, 16, 24, 48, 96})
 	{
 	{
 		const String rml_document = CreateString(rml_font_texture_atlas_document.c_str(), font_size);
 		const String rml_document = CreateString(rml_font_texture_atlas_document.c_str(), font_size);
 
 
-		ElementDocument *const document = context->LoadDocumentFromMemory(rml_document);
+		ElementDocument* const document = context->LoadDocumentFromMemory(rml_document);
 		REQUIRE(document);
 		REQUIRE(document);
-		Element *const body = document->GetElementById("body");
+		Element* const body = document->GetElementById("body");
 		REQUIRE(body);
 		REQUIRE(body);
 		document->Show();
 		document->Show();
 		context->Update();
 		context->Update();
@@ -55,19 +65,34 @@ TEST_CASE("font_texture_atlas")
 
 
 		for (const int glyph_count : {10, 100, 1000})
 		for (const int glyph_count : {10, 100, 1000})
 		{
 		{
-			String benchmark_name;
-			FormatString(benchmark_name, "Size %d with %d glyphs", font_size, glyph_count);
-			bench.run(benchmark_name.c_str(), [&]() {
-				ReleaseFontResources();
-				for (int i = 0; i < glyph_count; ++i)
-				{
-					body->SetInnerRML(StringUtilities::ToUTF8(static_cast<Character>(
-						rml_font_texture_atlas_start_codepoint + i
-					)));
+			const String benchmark_name = CreateString("Size %d with %d glyphs", font_size, glyph_count);
+
+			if (incremental)
+			{
+				bench.run(benchmark_name, [&]() {
+					ReleaseFontResources();
+					std::string inner_rml;
+					for (int i = 0; i < glyph_count; ++i)
+					{
+						inner_rml += StringUtilities::ToUTF8(static_cast<Character>(rml_font_texture_atlas_start_codepoint + i));
+						body->SetInnerRML(inner_rml);
+					}
 					context->Update();
 					context->Update();
 					context->Render();
 					context->Render();
-				}
-			});
+				});
+			}
+			else
+			{
+				bench.run(benchmark_name, [&]() {
+					ReleaseFontResources();
+					for (int i = 0; i < glyph_count; ++i)
+					{
+						body->SetInnerRML(StringUtilities::ToUTF8(static_cast<Character>(rml_font_texture_atlas_start_codepoint + i)));
+						context->Update();
+						context->Render();
+					}
+				});
+			}
 		}
 		}
 
 
 		document->Close();
 		document->Close();