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.
#Region "[=== OPTIONS ===]"

Option Strict On
Option Explicit On
Option Compare Binary

#End Region

''' <summary>
''' clsSpeedTestAB_Delegates - Speed test Select-Case and Delegate Functions.
''' </summary>
''' <overview>
''' </overview>
''' <remarks>
''' </remarks>
''' <notes>
''' </notes>
Public Class clsSpeedTestAB_Delegates
  Inherits ZED.Utility.Development.clsBaseSpeedTestAB

#Region "[=== CONSTRUCTORS DESTRUCTORS INITIALISATION ===]"

  ''' <summary>
  ''' Construct a new speed test with prescribed repetitions.
  ''' </summary>
  ''' <param name="aRepetitions"></param>
  ''' <remarks></remarks>
  Public Sub New(ByVal aRepetitions As Int32)
    MyBase.New(aRepetitions)
  End Sub

#End Region

#Region "[=== SPEED TEST COMPONENTS ===]"

  Protected Function PR_GetIndex_Format1bppIndexed _
        (ByVal aMap As Int32, ByVal aCol As Int32) As Int32
    Return CByte((aMap >> (7 - (aCol Mod 8))) And 1)
  End Function

  Protected Function PR_GetIndex_Format4bppIndexed _
        (ByVal aMap As Int32, ByVal aCol As Int32) As Int32
    Return CByte((aMap >> ((aCol Mod 2) * 4)) And 15)
  End Function

  Protected Function PR_GetIndex_Format8bppIndexed _
        (ByVal aMap As Int32, ByVal aCol As Int32) As Int32
    ' Return the 8-bit index.
    Return aMap
  End Function

  Protected Delegate Function DelegateFunction _
        (ByVal aMap As Int32, ByVal aCol As Int32) As Int32

  Protected f_Col As Int32 = 1234
  Protected f_Map As Int32 = 187

  Protected f_Function As Int32 = 4

  Protected f_Delegate As DelegateFunction

#End Region

#Region "[=== SPEED TEST OVERRIDE METHODS ===]"

  ''' <summary>
  ''' Overriden speed test A setup.
  ''' </summary>
  ''' <remarks></remarks>
  Protected Overrides Sub SetUpTestB()
    Me.f_DescribeB = "Call functions directly from Select Case."
  End Sub

  ''' <summary>
  ''' Overriden speed test A setup.
  ''' </summary>
  ''' <remarks></remarks>
  Protected Overrides Sub SetUpTestA()
    Me.f_DescribeA = "Call functions indirectly by delegate."
    Me.f_Delegate = AddressOf Me.PR_GetIndex_Format4bppIndexed
  End Sub

  ''' <summary>
  ''' Overridden Speed Test B.
  ''' </summary>
  ''' <remarks></remarks>
  Protected Overrides Sub SpeedTestB()
    Dim xInt As Int32
    Select Case Me.f_Function
      Case 1
        xInt = Me.PR_GetIndex_Format1bppIndexed(Me.f_Map, Me.f_Col)
      Case 4
        xInt = Me.PR_GetIndex_Format4bppIndexed(Me.f_Map, Me.f_Col)
      Case 8
        xInt = Me.PR_GetIndex_Format8bppIndexed(Me.f_Map, Me.f_Col)
    End Select
  End Sub

  ''' <summary>
  ''' Overridden Speed Test A.
  ''' </summary>
  ''' <remarks></remarks>
  Protected Overrides Sub SpeedTestA()
    Dim xInt As Int32
    xInt = Me.f_Delegate(Me.f_Map, Me.f_Col)
  End Sub

#End Region

End Class

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
Web01 | 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