{"id":19626598,"url":"https://github.com/softcircuits/performancetester","last_synced_at":"2026-06-18T09:32:04.298Z","repository":{"id":98675168,"uuid":"265678343","full_name":"SoftCircuits/PerformanceTester","owner":"SoftCircuits","description":"Simple class to help compare the performance of different algorithms.","archived":false,"fork":false,"pushed_at":"2021-10-17T18:21:20.000Z","size":68,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-10T14:50:37.139Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SoftCircuits.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-20T20:23:59.000Z","updated_at":"2022-11-14T05:07:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"271f3d52-f174-47d7-b83c-259ee397fa36","html_url":"https://github.com/SoftCircuits/PerformanceTester","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCircuits%2FPerformanceTester","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCircuits%2FPerformanceTester/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCircuits%2FPerformanceTester/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCircuits%2FPerformanceTester/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SoftCircuits","download_url":"https://codeload.github.com/SoftCircuits/PerformanceTester/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240926398,"owners_count":19879737,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T11:47:07.085Z","updated_at":"2026-06-18T09:32:04.130Z","avatar_url":"https://github.com/SoftCircuits.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PerformanceTester\n\n[![NuGet version (SoftCircuits.PerformanceTester)](https://img.shields.io/nuget/v/SoftCircuits.PerformanceTester.svg?style=flat-square)](https://www.nuget.org/packages/SoftCircuits.PerformanceTester/)\n\n```\nInstall-Package SoftCircuits.PerformanceTester\n```\n\n## Introduction\n\nPerformanceTester is a simple library to help compare the performance of different algorithms. If you have several ways of solving a problem where performance is a concern, use this library as a framework to quickly show the relative performance of different candidates.\n\n## Creating Tests\n\nYou create a test by creating a class that implements `IPerformanceTest`. This interface has three members:\n\n```cs\npublic string Description { get; }\n```\n\n`Description` is a read-only property that describes this test.\n\n```cs\npublic void Initialize(object? data);\n```\n\n`Initialize` is a method to perform any initialization for the test. The time taken by this method is not included in the results. The `data` argument can optionally be used to pass data to the test.\n\n```cs\npublic void Run(object? data);\n```\n\n`Run` is the method that performs the actual test. This is the method that will be timed. The `data` argument can optionally be used to pass data to the test.\n\nThe following code defines three simple tests. These tests simply call `Thread.Sleep()` to pause for varying amounts of time.\n\n```cs\nclass Test1 : IPerformanceTest\n{\n    public string Description =\u003e \"Quarter second test\";\n    public void Initialize(object? data) { }\n    public void Run(object? data) =\u003e Thread.Sleep(250);\n}\n\nclass Test2 : IPerformanceTest\n{\n    public string Description =\u003e \"Half second test\";\n    public void Initialize(object? data) { }\n    public void Run(object? data) =\u003e Thread.Sleep(500);\n}\n\nclass Test3 : IPerformanceTest\n{\n    public string Description =\u003e \"One second test\";\n    public void Initialize(object? data) { }\n    public void Run(object? data) =\u003e Thread.Sleep(1000);\n}\n```\n\n## Running the Tests\n\nTo test the performance of the tests you've created, create an instance of the `PerformanceTester` class and call the `Run()` method. This method has many overloads to support different scenarios. Often, the easiest way to call this method is by providing the current assembly. In this case, the `Run()` method will run all the tests (classes that implement `IPerformanceTest`) in the given assembly.\n\n```cs\nPerformanceTester tester = new PerformanceTester();\nIEnumerable\u003cTestResult\u003e results = tester.Run(Assembly.GetExecutingAssembly());\n```\n\nMost of the `Run()` overloads include an optional `iterations` and `data` argument.\n\nThe `iterations` argument specifies how many times to run each test. This can be handy when the test is too quick to measure, or if the test execution time can vary and you want to compare the average time to perform each test. When running more than one iteration, you can set the `PerformanceTester.AverateResults` property to `true`. In this case, the results will show the average time rather than the total time.\n\nThe `data` argument is simply an argument that gets pass to each test. You might using for sending test data, for example. Because this argument is of type `object`, it can pass any type of data.\n\n## Displaying Test Results\n\nThe `Run()` methods return an `IEnumerable` of type `TestResult`. The `TestResult` class provides the description of the test, the number of milliseconds taken by that test, and also the percent of time taken relative to the slowest test.\n\nThe `TestResult` class also provides the `GetRelativePerformanceBar()` method. This method will create a character *bar* that represents the result's relative time. This is demonstrated in the following snippet.\n\n```cs\nforeach (TestResult result in results)\n{\n    Console.WriteLine(\"{0} ({1}ms)\", result.Description, result.Milliseconds);\n    Console.WriteLine(\"[{0}]\", result.GetRelativePerformanceBar(60));\n    Console.WriteLine();\n}\n```\n\nThe code above produces the following output.\n\n```\nQuarter second test (255ms)\n[***************                                             ]\n\nHalf second test (500ms)\n[*****************************                               ]\n\nOne second test (1001ms)\n[************************************************************]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftcircuits%2Fperformancetester","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftcircuits%2Fperformancetester","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftcircuits%2Fperformancetester/lists"}