Click here to Skip to main content
12,255,210 members (60,178 online)
Click here to Skip to main content
Articles » Languages » C# » Utilities » Downloads

Stats

17.6K 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.
Public Class Form1

  Private TestProperties As clsSpeedTestAB_Properties
  Private TestRecursion As clsSpeedTestAB_Recursion
  Private BadNumber As Boolean

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.RichTextBox1.Clear()
  End Sub

  Private Sub textBox1_KeyDown _
        (ByVal sender As Object _
        , ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    ' Initialize the flag to false.
    Me.BadNumber = False
    ' Determine whether the keystroke is a number from the top of the keyboard.
    If e.KeyCode < Keys.D0 OrElse e.KeyCode > Keys.D9 Then
      ' Determine whether the keystroke is a number from the keypad.
      If e.KeyCode < Keys.NumPad0 OrElse e.KeyCode > Keys.NumPad9 Then
        ' Determine whether the keystroke is a backspace.
        If e.KeyCode <> Keys.Back Then
          ' A non-numerical keystroke was pressed. 
          ' Set the flag to true and evaluate in KeyPress event.
          Me.BadNumber = True
        End If
      End If
    End If
  End Sub

  Private Sub textBox1_KeyPress _
        (ByVal sender As Object _
        , ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    ' Check for the flag being set in the KeyDown event.
    If Me.BadNumber = True Then
      ' Stop the character from being entered into the control since it is non-numerical.
      e.Handled = True
    End If
  End Sub

  Private Sub Button2_Click _
        (ByVal sender As System.Object _
        , ByVal e As System.EventArgs) Handles Button2.Click
    Dim xTest As New clsSpeedTestAB_Delegates(CInt(Me.TextBox1.Text) * 100)
    xTest.RunTest()
    Me.RichTextBox1.SelectedText = vbCrLf + xTest.Results
    Me.RichTextBox1.ScrollToCaret()
    Me.RichTextBox1.Refresh()
  End Sub

  Private Sub Button3_Click _
        (ByVal sender As System.Object _
        , ByVal e As System.EventArgs) Handles Button3.Click
    Dim xTest As New clsSpeedTestAB_Properties(CInt(Me.TextBox1.Text) * 100)
    xTest.RunTest()
    Me.RichTextBox1.SelectedText = vbCrLf + xTest.Results
    Me.RichTextBox1.ScrollToCaret()
    Me.RichTextBox1.Refresh()
  End Sub

  Private Sub Button4_Click _
        (ByVal sender As System.Object _
        , ByVal e As System.EventArgs) Handles Button4.Click
    Dim xTest As New clsSpeedTestAB_Recursion(CInt(Me.TextBox1.Text))
    xTest.RunTest()
    Me.RichTextBox1.SelectedText = vbCrLf + xTest.Results
    Me.RichTextBox1.ScrollToCaret()
    Me.RichTextBox1.Refresh()
  End Sub

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.160426.1 | Last Updated 29 May 2008
Article Copyright 2008 by Warrick Procter
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid