Unosquare
    Show / Hide Table of Contents

    Class Benchmark

    A simple benchmarking class.

    Inheritance
    Object
    Benchmark
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Swan.Diagnostics
    Syntax
    public static class Benchmark
    Examples

    The following code demonstrates how to create a simple benchmark.

    namespace Examples.Benchmark.Simple
    {
        using Swan.Diagnostics;
    
        public class SimpleBenchmark
        {
            public static void Main()
            {
                 using (Benchmark.Start("Test"))
                 {
                    // do some logic in here
                 }
    
                // dump results into a string
                var results = Benchmark.Dump();
            }
        }
    
    }

    Methods

    BenchmarkAction(Action)

    Measures the elapsed time of the given action as a TimeSpan This method uses a high precision Stopwatch if it is available.

    Declaration
    public static TimeSpan BenchmarkAction(Action target)
    Parameters
    Type Name Description
    Action target

    The target.

    Returns
    Type Description
    TimeSpan

    A time interval that represents a specified time, where the specification is in units of ticks.

    Dump()

    Outputs the benchmark statistics.

    Declaration
    public static string Dump()
    Returns
    Type Description
    String

    A string containing human-readable statistics.

    Start(String)

    Starts measuring with the given identifier.

    Declaration
    public static IDisposable Start(string identifier)
    Parameters
    Type Name Description
    String identifier

    The identifier.

    Returns
    Type Description
    IDisposable

    A disposable object that when disposed, adds a benchmark result.

    Comments

    Back to top Copyright © 2017-2019 Unosquare