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

Comparative Speed Testing

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

/// <summary>
/// clsSpeedTestAB_Delegates - Speed test Select-Case and Delegate Functions.
/// </summary>
/// <overview>
/// </overview>
/// <remarks>
/// </remarks>
/// <notes>
/// </notes>
public class clsSpeedTestAB_Delegates : clsBaseSpeedTestAB
{
    protected int f_Col;
    protected DelegateFunction f_Delegate;
    protected int f_Function;
    protected int f_Map;

    /// <summary>
    /// Construct a new speed test with prescribed repetitions.
    /// </summary>
    /// <param name="aRepetitions"></param>
    /// <remarks></remarks>
    public clsSpeedTestAB_Delegates(int aRepetitions) : base(aRepetitions)
    {
        this.f_Col = 0x4d2;
        this.f_Map = 0xbb;
        this.f_Function = 4;
    }

    protected int PR_GetIndex_Format1bppIndexed(int aMap, int aCol)
    {
        return (byte) ((aMap >> (7 - (aCol % 8))) & 1);
    }

    protected int PR_GetIndex_Format4bppIndexed(int aMap, int aCol)
    {
        return (byte) ((aMap >> ((aCol % 2) * 4)) & 15);
    }

    protected int PR_GetIndex_Format8bppIndexed(int aMap, int aCol)
    {
        return aMap;
    }

    /// <summary>
    /// Overriden speed test A setup.
    /// </summary>
    /// <remarks></remarks>
    protected override void SetUpTestA()
    {
        base.f_DescribeA = "Call functions indirectly by delegate.";
        this.f_Delegate = new DelegateFunction(this.PR_GetIndex_Format4bppIndexed);
    }

    /// <summary>
    /// Overriden speed test A setup.
    /// </summary>
    /// <remarks></remarks>
    protected override void SetUpTestB()
    {
        base.f_DescribeB = "Call functions directly from Select Case.";
    }

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

    /// <summary>
    /// Overridden Speed Test B.
    /// </summary>
    /// <remarks></remarks>
    protected override void SpeedTestB()
    {
        int xInt;
        switch (this.f_Function)
        {
            case 1:
                xInt = this.PR_GetIndex_Format1bppIndexed(this.f_Map, this.f_Col);
                break;

            case 4:
                xInt = this.PR_GetIndex_Format4bppIndexed(this.f_Map, this.f_Col);
                break;

            case 8:
                xInt = this.PR_GetIndex_Format8bppIndexed(this.f_Map, this.f_Col);
                break;
        }
    }

    protected delegate int DelegateFunction(int aMap, int aCol);
}

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 | Mobile
Web02 | 2.8.140916.1 | Last Updated 29 May 2008
Article Copyright 2008 by Warrick Procter
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid