Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Utilities » Downloads
 
Add your own
alternative version

Comparative Speed Testing

, 28 May 2008 CPOL
A simple-to-use class for performing comparative, non-benchmarked speed tests when optimising code for execution speed.
using System;
using ZED.Utility.Development;

/// <summary>
/// clsSpeedTestAB_Properties - Speed test Property versus direct field access.
/// </summary>
/// <overview>
/// </overview>
/// <remarks>
/// </remarks>
/// <notes>
/// </notes>
public class clsSpeedTestAB_Properties : clsBaseSpeedTestAB
{
    protected int f_SomeInteger;

    /// <summary>
    /// Construct a new speed test with prescribed repetitions.
    /// </summary>
    /// <param name="aRepetitions"></param>
    /// <remarks></remarks>
    public clsSpeedTestAB_Properties(int aRepetitions) : base(aRepetitions)
    {
        this.f_SomeInteger = 0x1e240;
    }

    /// <summary>
    /// Overriden speed test A setup.
    /// </summary>
    /// <remarks></remarks>
    protected override void SetUpTestA()
    {
        base.f_DescribeA = "Access a public field directly.";
    }

    /// <summary>
    /// Overriden speed test A setup.
    /// </summary>
    /// <remarks></remarks>
    protected override void SetUpTestB()
    {
        base.f_DescribeB = "Access a field via a property.";
    }

    /// <summary>
    /// Overridden Speed Test A.
    /// </summary>
    /// <remarks></remarks>
    protected override void SpeedTestA()
    {
        int xInt = this.f_SomeInteger;
    }

    /// <summary>
    /// Overridden Speed Test B.
    /// </summary>
    /// <remarks></remarks>
    protected override void SpeedTestB()
    {
        int xInt = this.SomeInteger;
    }

    public int SomeInteger
    {
        get
        {
            return this.f_SomeInteger;
        }
        set
        {
            this.f_SomeInteger = value;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Warrick Procter
ZED
New Zealand New Zealand
A DEC PDP/11 BasicPlus2 developer from the 80s.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150123.1 | Last Updated 29 May 2008
Article Copyright 2008 by Warrick Procter
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid