{"id":92098,"date":"2023-07-10T08:00:30","date_gmt":"2023-07-10T06:00:30","guid":{"rendered":"https:\/\/code-maze.com\/?p=92098"},"modified":"2024-03-22T12:22:53","modified_gmt":"2024-03-22T11:22:53","slug":"how-to-integrate-benchmarkdotnet-with-unit-tests","status":"publish","type":"post","link":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/","title":{"rendered":"How to Integrate BenchmarkDotNet With Unit Tests"},"content":{"rendered":"<p>In this article, we will learn how to integrate BenchmarkDotNet with Unit Tests and use some advanced APIs of the BenchmarkDotNet library when doing that.<\/p>\n<p>In the .NET ecosystem, <a href=\"https:\/\/code-maze.com\/benchmarking-csharp-and-asp-net-core-projects\/\" target=\"_blank\" rel=\"noopener\">BenchmarkDotNet<\/a> is the go-to library for conducting performance benchmarks. Typically we encounter this library being used in a console application to run these benchmarks. However, the process is manual, requiring developers to trigger the application and examine the results on the console.<\/p>\n<p><strong>Automating these benchmark tests and validating the resulting values would be incredibly helpful by incorporating them into unit tests<\/strong>. By doing so, we can execute these unit tests as part of our CI\/CD pipeline, enabling us to receive continuous feedback on our code performance after each build.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/dotnet-client-libraries\/BenchmarkDotNetWithUnitTests\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s dive in.<\/p>\n<h2>Benchmark Test Cases<\/h2>\n<p>We will keep the benchmark tests code simple, showcasing the various string concatenation techniques in C#. This is the summary of the test results executed on our machine (keep in mind that benchmark results may differ across various machines):\u00a0<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">|               Method |       Mean |     Error |    StdDev |     Median | Rank |   Gen0 | Allocated |\r\n|--------------------- |-----------:|----------:|----------:|-----------:|-----:|-------:|----------:|\r\n|         StringConcat |  0.0000 ns | 0.0000 ns | 0.0000 ns |  0.0000 ns |    1 |      - |         - |\r\n|  StringInterpolation |  0.0091 ns | 0.0133 ns | 0.0124 ns |  0.0005 ns |    1 |      - |         - |\r\n| StringConcatWithJoin | 28.0945 ns | 0.4573 ns | 0.4054 ns | 27.9739 ns |    2 | 0.0095 |      80 B |\r\n|         StringFormat | 66.2081 ns | 0.7046 ns | 0.6591 ns | 66.1982 ns |    3 | 0.0048 |      40 B |\r\n<\/pre>\n<p>We will be focussing only on the <code>StringInterpolation<\/code> test case and assert its values. <strong>As the execution of benchmark test cases can take considerable time, we want to run the performance benchmark only once<\/strong>. To achieve this, we will utilize the xUnit <code>TestFixture<\/code> class.<\/p>\n<p>Let&#8217;s look at the code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">  \r\nusing BenchmarkDotNet.Configs;\r\nusing BenchmarkDotNet.Order;\r\nusing BenchmarkDotNet.Reports;\r\nusing BenchmarkDotNet.Running;\r\nusing BenchmarkDotNetWithUnitTests;\r\n\r\nnamespace Tests;\r\n\r\npublic class BenchmarkFixture\r\n{\r\n    public Summary BenchmarkSummary { get; }\r\n    public BenchmarkFixture()\r\n    {\r\n        var config = new ManualConfig\r\n        {\r\n            SummaryStyle = SummaryStyle.Default.WithMaxParameterColumnWidth(100),\r\n            Orderer = new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest),\r\n            Options = ConfigOptions.Default\r\n        };\r\n\r\n        BenchmarkSummary = BenchmarkRunner.Run(config);\r\n    }\r\n}\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">In the constructor, we run the string concat benchmarks with the appropriate configuration, exposing the results as the <code>BenchmarkSummary<\/code> property of type <code>Summary<\/code><\/span><span style=\"font-weight: 400;\">. <\/span>We then initialize this property in the class constructor.<\/p>\n<p>So now the text fixture class is done, let&#8217;s use it in our test class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class StringConcatBenchmarkLiveTest : IClassFixture\r\n{\r\n    private readonly ImmutableArray&lt;BenchmarkReport&gt; _benchmarkReports;\r\n    private readonly BenchmarkReport _stringInterpolationReport;\r\n\r\n    public StringConcatBenchmarkLiveTest(BenchmarkFixture benchmarkFixture)\r\n    {\r\n        _benchmarkReports = benchmarkFixture.BenchmarkSummary.Reports;\r\n        _stringInterpolationReport = _benchmarkReports.First(x =&gt;\r\n            x.BenchmarkCase.Descriptor.DisplayInfo == \"StringConcatBenchmarks.StringInterpolation\");\r\n    }\r\n}<\/pre>\n<p>We hold the reference to the benchmark&#8217;s calculated reports and assign it to an immutable collection field <code>_benchmarkReports<\/code>. Additionally, we fetch the report related to <code>StringInterpolation<\/code> and hold a reference on the <code>_stringInterpolationReport<\/code>\u00a0field. Both these fields are used on test assertions.<\/p>\n<h2>Integrate BenchmarkDotNet With Unit Tests By Asserting the Count<\/h2>\n<p>Now that the test setup is complete, it&#8217;s time to execute the tests. Firstly, let&#8217;s go over the basics. We need to validate the number of test cases that are being executed.<\/p>\n<p>Let&#8217;s understand with the code snippet:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Fact]\r\npublic void WhenBenchmarkTestsAreRun_ThenFourCasesMustBeExecuted()\r\n{\r\n    var benchmarkCases = _benchmarkReports.Length;\r\n    \r\n    Assert.Equal(4, benchmarkCases);\r\n}<\/pre>\n<p>We create a\u00a0<code>benchmarkCases<\/code> variable and check if its value, which is the number of benchmark reports in the array, equals 4 using xUnit&#8217;s <code>Assert.Equal()<\/code>. If not, then the test fails.<\/p>\n<h2>Asserting the Speed<\/h2>\n<p>After verifying the count, we can proceed to test the execution speed of the <code>StringInterpolation<\/code> benchmark case:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Fact]\r\npublic void WhenStringInterpolationCaseIsExecuted_ThenItShouldNotTakeMoreThanFifteenNanoSecs()\r\n{\r\n    var stats = _stringInterpolationReport.ResultStatistics;\r\n    \r\n    Assert.True(stats is { Mean: &lt; 15 }, $\"Mean was {stats.Mean}\");\r\n}<\/pre>\n<p>We need to obtain the statistical results of the benchmark case, and for that, we extract the <code>ResultStatistics<\/code> value from the <code>_stringInterpolationReport<\/code> object. We then verify the mean value of the result statistics (<code>stats.Mean<\/code>) using the <code>Assert.True()<\/code> method to ensure it is below 15 nanoseconds. If the condition is unmet, the test fails and displays a message containing the actual mean value.<\/p>\n<h2>Asserting the Memory Allocation<\/h2>\n<p>Let&#8217;s move on to some advanced stuff now by checking the memory allocation of the <code>StringInterpolation<\/code> code is within a particular threshold value:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Fact]\r\npublic void WhenStringInterpolationCaseIsExecuted_ThenItShouldNotConsumeMemoryMoreThanMaxAllocation()\r\n{\r\n    const int maxAllocation = 1342178216;\r\n   \u00a0var memoryStats = _stringInterpolationReport.GcStats;\r\n\u00a0 \u00a0\u00a0var stringInterpolationCase = _stringInterpolationReport.BenchmarkCase;\r\n\u00a0 \u00a0\u00a0var allocation = memoryStats.GetBytesAllocatedPerOperation(stringInterpolationCase);\r\n\u00a0 \u00a0\u00a0var totalAllocatedBytes = memoryStats.GetTotalAllocatedBytes(true);\r\n\r\n\u00a0 \u00a0\u00a0Assert.True(allocation &lt;= maxAllocation, $\"Allocation was {allocation}\");\r\n\u00a0 \u00a0\u00a0Assert.True(totalAllocatedBytes &lt;= maxAllocation,\r\n\u00a0 \u00a0 \u00a0 \u00a0\u00a0$\"TotalAllocatedBytes was {totalAllocatedBytes}\");\r\n}\r\n<\/pre>\n<p>We begin by defining a constant variable <code>maxAllocation<\/code> that represents the maximum allowed allocation. We then retrieve the garbage collection statistics (<code>GcStats<\/code>) of the benchmark case from the <code>_stringInterpolationReport<\/code> object. Then we also retrieve the benchmark case itself using the same object to obtain the <code>stringInterpolationCase<\/code>. After this, we calculate the allocation in bytes per operation by passing <code>stringInterpolationCase<\/code> it as a parameter to <code>GetBytesAllocatedPerOperation()<\/code> on the <code>memoryStats<\/code> object.<\/p>\n<p>We validate two conditions using the <code>Assert.True()<\/code> method for validating memory allocated per operation and total memory allocated for all operations:<\/p>\n<ul>\n<li>We check if the allocation per operation (<code>allocation<\/code>) is less than or equal to the <code>maxAllocation<\/code>. If the condition is false, the test fails with a failure message, including the actual allocation.<\/li>\n<li>We also check if the total allocated bytes (<code>memoryStats.GetTotalAllocatedBytes(true)<\/code>) is less than or equal to the <code>maxAllocation<\/code>. If the condition is false, the test fails with a failure message that includes the total allocated bytes.<\/li>\n<\/ul>\n<h2>Asserting the Gen1 and Gen2 Allocation<\/h2>\n<p>We&#8217;ll now look closer at memory allocations and examine the Gen0 and Gen1 allocations for the <code>StringInterpolation<\/code> benchmark case:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Fact]\r\npublic void WhenStringInterpolationCaseIsExecuted_ThenZeroAllocationInGen1AndGen2()\r\n{\r\n    var memoryStats = _stringInterpolationReport.GcStats;\r\n    \r\n    Assert.True(memoryStats.Gen1Collections == 0, $\"Gen1Collections was {memoryStats.Gen1Collections}\");\r\n    Assert.True(memoryStats.Gen2Collections == 0, $\"Gen2Collections was {memoryStats.Gen2Collections}\");\r\n}\r\n<\/pre>\n<p>We retrieve the garbage collection statistics (<code>GcStats<\/code>) of the benchmark case from the <code>_stringInterpolationReport<\/code> object. We then use the <code>Assert.True()<\/code> method is used to perform two assertions.<\/p>\n<p>First, we check if the number of Gen1 garbage collections (<code>memoryStats.Gen1Collections<\/code>) is equal to zero. If the condition is false, the test fails with a failure message, including the number of Gen1 collections.<\/p>\n<p>Then, we check if the number of Gen2 garbage collections (<code>memoryStats.Gen2Collections<\/code>) is equal to zero. If the condition is false, the test fails with a failure message, including the actual number of Gen2 collections.<\/p>\n<h2>Conclusion<\/h2>\n<p>It&#8217;s not enough to measure performance once and be done with it. In this article, we discussed how to integrate BenchmarkDotNet with unit tests and emphasize the significance of that integration. This approach provides ongoing feedback on our code and boosts our confidence when making significant changes.<\/p>\n<p>We also explore utilizing advanced APIs to measure crucial factors of the benchmark, like speed and memory allocations. Automation is critical, and we covered how to achieve it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will learn how to integrate BenchmarkDotNet with Unit Tests and use some advanced APIs of the BenchmarkDotNet library when doing that. In the .NET ecosystem, BenchmarkDotNet is the go-to library for conducting performance benchmarks. Typically we encounter this library being used in a console application to run these benchmarks. However, the [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[2134,1112],"tags":[853,112,913,1113,580],"class_list":["post-92098","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-performance","category-testing","tag-benchmarkdotnet","tag-continuous-integration","tag-performance","tag-unit-tests","tag-xunit","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Integrate BenchmarkDotNet With Unit Tests - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we will learn how to integrate BenchmarkDotNet with unit tests by using some advanced BenchmarkDotNet APIs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Integrate BenchmarkDotNet With Unit Tests - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we will learn how to integrate BenchmarkDotNet with unit tests by using some advanced BenchmarkDotNet APIs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T06:00:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-22T11:22:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"How to Integrate BenchmarkDotNet With Unit Tests\",\"datePublished\":\"2023-07-10T06:00:30+00:00\",\"dateModified\":\"2024-03-22T11:22:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/\"},\"wordCount\":838,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"BenchmarkDotNet\",\"Continuous Integration\",\"Performance\",\"Unit tests\",\"xUnit\"],\"articleSection\":[\"Performance\",\"Testing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/\",\"url\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/\",\"name\":\"How to Integrate BenchmarkDotNet With Unit Tests - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2023-07-10T06:00:30+00:00\",\"dateModified\":\"2024-03-22T11:22:53+00:00\",\"description\":\"In this article, we will learn how to integrate BenchmarkDotNet with unit tests by using some advanced BenchmarkDotNet APIs.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Integrate BenchmarkDotNet With Unit Tests\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Integrate BenchmarkDotNet With Unit Tests - Code Maze","description":"In this article, we will learn how to integrate BenchmarkDotNet with unit tests by using some advanced BenchmarkDotNet APIs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/","og_locale":"en_US","og_type":"article","og_title":"How to Integrate BenchmarkDotNet With Unit Tests - Code Maze","og_description":"In this article, we will learn how to integrate BenchmarkDotNet with unit tests by using some advanced BenchmarkDotNet APIs.","og_url":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/","og_site_name":"Code Maze","article_published_time":"2023-07-10T06:00:30+00:00","article_modified_time":"2024-03-22T11:22:53+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"How to Integrate BenchmarkDotNet With Unit Tests","datePublished":"2023-07-10T06:00:30+00:00","dateModified":"2024-03-22T11:22:53+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/"},"wordCount":838,"commentCount":1,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["BenchmarkDotNet","Continuous Integration","Performance","Unit tests","xUnit"],"articleSection":["Performance","Testing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/","url":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/","name":"How to Integrate BenchmarkDotNet With Unit Tests - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2023-07-10T06:00:30+00:00","dateModified":"2024-03-22T11:22:53+00:00","description":"In this article, we will learn how to integrate BenchmarkDotNet with unit tests by using some advanced BenchmarkDotNet APIs.","breadcrumb":{"@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/how-to-integrate-benchmarkdotnet-with-unit-tests\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"How to Integrate BenchmarkDotNet With Unit Tests"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/92098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=92098"}],"version-history":[{"count":3,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/92098\/revisions"}],"predecessor-version":[{"id":92158,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/92098\/revisions\/92158"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=92098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=92098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=92098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}