- C# 7 and .NET Core 2.0 High Performance
- Ovais Mehboob Ahmed Khan
- 200字
- 2021-08-27 18:47:14
Setting parameters
In the previous example, we tested the method with only one value. Practically, when testing an enterprise application, we want to test it with different values to estimate the method's performance.
First of all, we can define a property for each parameter, set the Params attribute, and specify the value(s) for which we need that method to be tested. Then we can use that property in the code. BenchmarkRun automatically tests that method with all of the parameters and generates the report. Here is the complete code snippet of the TestBenchmark class:
public class TestBenchmark { [Params(10,20,30)] public int Len { get; set; } [Benchmark] public void Fibonacci() { int a = 0, b = 1, c = 0; Console.Write("{0} {1}", a, b); for (int i = 2; i < Len; i++) { c = a + b; Console.Write(" {0}", c); a = b; b = c; } } [Benchmark] public void FibonacciRecursive() { Fibonacci_Recursive(0, 1, 1, Len); } private void Fibonacci_Recursive(int a, int b, int counter, int len) { if (counter <= len) { Console.Write("{0} ", a); Fibonacci_Recursive(b, a + b, counter + 1, len); } } }
After running Benchmark, the following report is generated:

推薦閱讀
- Learning Spring Boot
- 分布式數據庫系統:大數據時代新型數據庫技術(第3版)
- 大數據算法
- 大話Oracle Grid:云時代的RAC
- 大數據營銷:如何讓營銷更具吸引力
- 大數據Hadoop 3.X分布式處理實戰
- OracleDBA實戰攻略:運維管理、診斷優化、高可用與最佳實踐
- Learning Proxmox VE
- 數據中心數字孿生應用實踐
- 數據科學工程實踐:用戶行為分析與建模、A/B實驗、SQLFlow
- 計算機組裝與維護(微課版)
- 數字IC設計入門(微課視頻版)
- 大數據分析:數據倉庫項目實戰
- Expert Python Programming(Third Edition)
- 利用Python進行數據分析(原書第2版)