Click here to Skip to main content
12,354,086 members (68,227 online)
Click here to Skip to main content
Articles » Languages » C# » Utilities » Downloads

Stats

17.8K views
481 downloads
15 bookmarked
Posted

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

Option Strict On
Option Explicit On
Option Compare Binary

#End Region

''' <summary>
''' clsSpeedTestAB_Recursion - Speed test Stack-Push-Loop versus Recursive method calls.
''' </summary>
''' <overview>
''' </overview>
''' <remarks>
''' </remarks>
''' <notes>
''' </notes>
Public Class clsSpeedTestAB_Recursion
  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 Const kMAX As Int32 = 100

#End Region

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

  ''' <summary>
  ''' Overriden speed test B setup.
  ''' </summary>
  ''' <remarks></remarks>
  Protected Overrides Sub SetUpTestB()
    Me.f_DescribeA = "Loop, pushing data on a stack."
  End Sub

  ''' <summary>
  ''' Overriden speed test A setup.
  ''' </summary>
  ''' <remarks></remarks>
  Protected Overrides Sub SetUpTestA()
    Me.f_DescribeB = "Loop, calling a function recursively."
  End Sub

  ''' <summary>
  ''' Overridden Speed Test B.
  ''' </summary>
  ''' <remarks></remarks>
  Protected Overrides Sub SpeedTestB()
    Me.TestB(0)
  End Sub

  ''' <summary>
  ''' Overridden Speed Test A.
  ''' </summary>
  ''' <remarks></remarks>
  Protected Overrides Sub SpeedTestA()
    Me.TestA(0)
  End Sub

  Protected Sub TestB(ByVal aNumber As Int32)
    Dim xStack As New Stack
    Dim xDone As Boolean = False
    Dim xDecrease As Boolean = False
    Dim xMax As Int32 = aNumber + kMAX
    Dim xNumber As Int32 = aNumber

    Do While True
      If xDecrease Then
        xNumber = CInt(xStack.Pop)
        If xNumber = aNumber Then Return
      Else
        xStack.Push(xNumber)
        If xNumber = xMax Then
          xDecrease = True
        Else
          xNumber += 1
        End If
      End If
    Loop

  End Sub

  Protected Sub TestA(ByVal aNumber As Int32)
    If aNumber = kMAX Then
      Return
    Else
      Me.TestA(aNumber + 1)
    End If
  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.

You may also be interested in...

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