Find Execution time of a Method

后端 未结 5 1121
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 03:19

I am making an Image Steganography project for my college. I have finished the project and have kept several different algorithms for hiding data in images.

What I want

5条回答
  •  不思量自难忘°
    2021-02-06 03:59

    You can also use BenchmarkDotNet

    Then you do:

    1) Create a console project with a reference to the code you want to test.

    using BenchmarkDotNet.Running;
    using BenchmarkDotNet.Attributes;
    class Program
    {
        static void Main()
        {
            var summary = BenchmarkRunner.Run();
        }
    }
    
    public class YourBenchmarks
    {
        [Benchmark]
        public object HideDataUsingAlgorithm()
        {
            return Namespace.hideDataUsingAlgorithm(); // call the code you want to benchmark here
        }
    }
    

    2) Build in release and run without debugger.

    3) Open the report that is in the bin/release/YourBenchmarks-report-stackoverflow.md

    The report contains Median and StdDev by default. BenchmarkDotNet takes care of warmups and launches the process a number of times to give accurate statistics.

    Sample report:

                     Method |      Median |    StdDev |
    ----------------------- |------------ |---------- |
     HideDataUsingAlgorithm | 252.4869 ns | 8.0261 ns |
    

    For configuration read the docs.

提交回复
热议问题