Click here to Skip to main content
15,886,563 members
Articles / Programming Languages / Visual Basic

Comparative Speed Testing

Rate me:
Please Sign up or sign in to vote.
3.57/5 (9 votes)
28 May 2008CPOL6 min read 29.1K   548   15  
A simple-to-use class for performing comparative, non-benchmarked speed tests when optimising code for execution speed.
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;

[DesignerGenerated]
public class Form1 : Form
{
    private static ArrayList __ENCList = new ArrayList();
    [AccessedThroughProperty("Button1")]
    private Button _Button1;
    [AccessedThroughProperty("Button2")]
    private Button _Button2;
    [AccessedThroughProperty("Button3")]
    private Button _Button3;
    [AccessedThroughProperty("Button4")]
    private Button _Button4;
    [AccessedThroughProperty("Label1")]
    private Label _Label1;
    [AccessedThroughProperty("RichTextBox1")]
    private RichTextBox _RichTextBox1;
    [AccessedThroughProperty("TextBox1")]
    private TextBox _TextBox1;
    private bool BadNumber;
    private IContainer components;
    private clsSpeedTestAB_Properties TestProperties;
    private clsSpeedTestAB_Recursion TestRecursion;

    [DebuggerNonUserCode]
    public Form1()
    {
        ArrayList list = __ENCList;
        lock (list)
        {
            __ENCList.Add(new WeakReference(this));
        }
        this.InitializeComponent();
    }

    private void Button1_Click(object sender, EventArgs e)
    {
        this.RichTextBox1.Clear();
    }

    private void Button2_Click(object sender, EventArgs e)
    {
        clsSpeedTestAB_Delegates xTest = new clsSpeedTestAB_Delegates(Conversions.ToInteger(this.TextBox1.Text) * 100);
        xTest.RunTest();
        this.RichTextBox1.SelectedText = "\r\n" + xTest.Results();
        this.RichTextBox1.ScrollToCaret();
        this.RichTextBox1.Refresh();
    }

    private void Button3_Click(object sender, EventArgs e)
    {
        clsSpeedTestAB_Properties xTest = new clsSpeedTestAB_Properties(Conversions.ToInteger(this.TextBox1.Text) * 100);
        xTest.RunTest();
        this.RichTextBox1.SelectedText = "\r\n" + xTest.Results();
        this.RichTextBox1.ScrollToCaret();
        this.RichTextBox1.Refresh();
    }

    private void Button4_Click(object sender, EventArgs e)
    {
        clsSpeedTestAB_Recursion xTest = new clsSpeedTestAB_Recursion(Conversions.ToInteger(this.TextBox1.Text));
        xTest.RunTest();
        this.RichTextBox1.SelectedText = "\r\n" + xTest.Results();
        this.RichTextBox1.ScrollToCaret();
        this.RichTextBox1.Refresh();
    }

    [DebuggerNonUserCode]
    protected override void Dispose(bool disposing)
    {
        try
        {
            if (((disposing && (this.components != null)) ? 1 : 0) != 0)
            {
                this.components.Dispose();
            }
        }
        finally
        {
            base.Dispose(disposing);
        }
    }

    [DebuggerStepThrough]
    private void InitializeComponent()
    {
        this.RichTextBox1 = new RichTextBox();
        this.Button1 = new Button();
        this.Button2 = new Button();
        this.Button3 = new Button();
        this.Button4 = new Button();
        this.TextBox1 = new TextBox();
        this.Label1 = new Label();
        this.SuspendLayout();
        this.RichTextBox1.Location = new Point(12, 0x29);
        this.RichTextBox1.Name = "RichTextBox1";
        this.RichTextBox1.Size = new Size(0x300, 0x201);
        this.RichTextBox1.TabIndex = 0;
        this.RichTextBox1.Text = "";
        this.Button1.Location = new Point(12, 12);
        this.Button1.Name = "Button1";
        this.Button1.Size = new Size(60, 0x17);
        this.Button1.TabIndex = 1;
        this.Button1.Text = "Clear";
        this.Button1.UseVisualStyleBackColor = true;
        this.Button2.Location = new Point(0x152, 12);
        this.Button2.Name = "Button2";
        this.Button2.Size = new Size(60, 0x17);
        this.Button2.TabIndex = 2;
        this.Button2.Text = "Test 1";
        this.Button2.UseVisualStyleBackColor = true;
        this.Button3.Location = new Point(0x194, 12);
        this.Button3.Name = "Button3";
        this.Button3.Size = new Size(60, 0x17);
        this.Button3.TabIndex = 3;
        this.Button3.Text = "Test 2";
        this.Button3.UseVisualStyleBackColor = true;
        this.Button4.Location = new Point(470, 12);
        this.Button4.Name = "Button4";
        this.Button4.Size = new Size(60, 0x17);
        this.Button4.TabIndex = 4;
        this.Button4.Text = "Test 3";
        this.Button4.UseVisualStyleBackColor = true;
        this.TextBox1.Location = new Point(0xc7, 14);
        this.TextBox1.Name = "TextBox1";
        this.TextBox1.Size = new Size(0x54, 20);
        this.TextBox1.TabIndex = 5;
        this.TextBox1.Text = "100000";
        this.Label1.AutoSize = true;
        this.Label1.Location = new Point(0x4e, 0x11);
        this.Label1.Name = "Label1";
        this.Label1.Size = new Size(0x73, 13);
        this.Label1.TabIndex = 6;
        this.Label1.Text = "Number of Repetitions:";
        this.Label1.TextAlign = ContentAlignment.MiddleRight;
        this.AutoScaleDimensions = new SizeF(6f, 13f);
        this.AutoScaleMode = AutoScaleMode.Font;
        this.ClientSize = new Size(0x318, 0x236);
        this.Controls.Add(this.Label1);
        this.Controls.Add(this.TextBox1);
        this.Controls.Add(this.Button4);
        this.Controls.Add(this.Button3);
        this.Controls.Add(this.Button2);
        this.Controls.Add(this.Button1);
        this.Controls.Add(this.RichTextBox1);
        this.FormBorderStyle = FormBorderStyle.Fixed3D;
        this.MaximizeBox = false;
        this.Name = "Form1";
        this.Text = "ZED Speed Test";
        this.ResumeLayout(false);
        this.PerformLayout();
    }

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
        this.BadNumber = false;
        if ((((((e.KeyCode < Keys.D0) || (e.KeyCode > Keys.D9)) ? 1 : 0) != 0) && ((((e.KeyCode < Keys.NumPad0) || (e.KeyCode > Keys.NumPad9)) ? 1 : 0) != 0)) && (e.KeyCode != Keys.Back))
        {
            this.BadNumber = true;
        }
    }

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (this.BadNumber)
        {
            e.Handled = true;
        }
    }

    internal virtual Button Button1
    {
        [DebuggerNonUserCode]
        get
        {
            return this._Button1;
        }
        [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
        set
        {
            if (this._Button1 != null)
            {
                this._Button1.Click -= new EventHandler(this.Button1_Click);
            }
            this._Button1 = value;
            if (this._Button1 != null)
            {
                this._Button1.Click += new EventHandler(this.Button1_Click);
            }
        }
    }

    internal virtual Button Button2
    {
        [DebuggerNonUserCode]
        get
        {
            return this._Button2;
        }
        [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
        set
        {
            if (this._Button2 != null)
            {
                this._Button2.Click -= new EventHandler(this.Button2_Click);
            }
            this._Button2 = value;
            if (this._Button2 != null)
            {
                this._Button2.Click += new EventHandler(this.Button2_Click);
            }
        }
    }

    internal virtual Button Button3
    {
        [DebuggerNonUserCode]
        get
        {
            return this._Button3;
        }
        [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
        set
        {
            if (this._Button3 != null)
            {
                this._Button3.Click -= new EventHandler(this.Button3_Click);
            }
            this._Button3 = value;
            if (this._Button3 != null)
            {
                this._Button3.Click += new EventHandler(this.Button3_Click);
            }
        }
    }

    internal virtual Button Button4
    {
        [DebuggerNonUserCode]
        get
        {
            return this._Button4;
        }
        [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
        set
        {
            if (this._Button4 != null)
            {
                this._Button4.Click -= new EventHandler(this.Button4_Click);
            }
            this._Button4 = value;
            if (this._Button4 != null)
            {
                this._Button4.Click += new EventHandler(this.Button4_Click);
            }
        }
    }

    internal virtual Label Label1
    {
        [DebuggerNonUserCode]
        get
        {
            return this._Label1;
        }
        [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
        set
        {
            this._Label1 = value;
        }
    }

    internal virtual RichTextBox RichTextBox1
    {
        [DebuggerNonUserCode]
        get
        {
            return this._RichTextBox1;
        }
        [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
        set
        {
            this._RichTextBox1 = value;
        }
    }

    internal virtual TextBox TextBox1
    {
        [DebuggerNonUserCode]
        get
        {
            return this._TextBox1;
        }
        [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
        set
        {
            if (this._TextBox1 != null)
            {
                this._TextBox1.KeyPress -= new KeyPressEventHandler(this.textBox1_KeyPress);
                this._TextBox1.KeyDown -= new KeyEventHandler(this.textBox1_KeyDown);
            }
            this._TextBox1 = value;
            if (this._TextBox1 != null)
            {
                this._TextBox1.KeyPress += new KeyPressEventHandler(this.textBox1_KeyPress);
                this._TextBox1.KeyDown += new KeyEventHandler(this.textBox1_KeyDown);
            }
        }
    }
}

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)


Written By
ZED
New Zealand New Zealand
A DEC PDP/11 BasicPlus2 developer from the 80s.

Comments and Discussions