locked
How to check computer performance?

    Question

  • Hi,

     

    My program do a lot of things and work slow, I want to tell the user if the performance of his computer are good or bad.

     

    I tried to do loop and to check the time that goes by, but I saw that the time is changing in the same computer

    everytime that I run my program, and if I compare the time with two computer (one P4 1.7 the other Dual core 2.4)

    sometime I get the same time.

     

    So I want to know if there other way to check the performance of the computer in VB?

     

    Best Regards,

    Yaniv

    Monday, October 22, 2007 9:24 AM

Answers

  •  

    It sounds as if your program is working because there is almost always something going on with all the other processes.

    One thing to be aware of is that if you are using timers, they almost significant inaccuracies. There are several ways to get around this. The API has high precision timer or you can use the the performance monitor class to get high precision clock ticks. Do not assume that a timer interval is overly meaningful. User a timer to tell you when to get the actual system time.

    Monday, October 22, 2007 11:38 AM
  • Use the stopwatch to do the timing.  Time a loop multiple times(at least 10) and get the mean and standard deviation.  If a time is more than 3 standard deviations from the mean, suspect the timing.  If you program uses a single tread, the times on your example computers would propably be about the same.  The dual core processor has more overhead coordinating the cores and, since it is probably in a later computer, has more processes running on it.

    Monday, October 22, 2007 1:23 PM
  • Hi Yaniv,

     

    The PerformanceCounter control can be used to count CPU usage.

     

    Prerequisites: PerformanceCounter1,Timer1, ProgressBar1 and Label1 on Form1.

    Code Block

    Imports Microsoft.VisualBasic

    Imports System

    Imports System.Collections.Generic

    Imports System.ComponentModel

    Imports System.Data

    Imports System.Drawing

    Imports System.Text

    Imports System.Windows.Forms

     

    Namespace CpuUsageTest

              Public Partial Class frmCpuUsage

                       Inherits Form

     

            Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

                timer1.Enabled = True

                performanceCounter1.CategoryName = "Processor"

                performanceCounter1.CounterName = "% Processor Time"

                performanceCounter1.InstanceName = "_Total"

            End Sub

     

            Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer1.Tick

                progressBar1.Value = CInt(Fix(performanceCounter1.NextValue()))

                label1.Text = "CPU Usage: " & progressBar1.Value.ToString() & "%"

            End Sub

     

        End Class

    End Namespace

     

    By the way, the statement can get the CPU count.

    Dim count As Int32 = System.Environment.ProcessorCount

     

    Please check this document for detail.

    Monitor and Display CPU State Information

    This article describes a quick and simple approach to displaying information about the state of the CPU or CPUs on a targeted machine.

     

    Regards,

    Martin

    Thursday, October 25, 2007 9:50 AM
  • You can get CPU speed from Registry like this:

    Code Block

    Imports Microsoft.Win32

    Public Class Form1

     

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

            Dim myReg As RegistryKey = Registry.LocalMachine

            Dim myRegKey As RegistryKey

            Dim myVal As String

            myRegKey = myReg.OpenSubKey("HARDWARE\DESCRIPTION\SYSTEM\CentralProcessor\0")

            myVal = myRegKey.GetValue("~Mhz").ToString

            myRegKey.Close()

            TextBox1.Text = String.Format("CPU Speed {0} M", myVal)

        End Sub

    End Class

     

     

    Thursday, October 25, 2007 10:02 AM

All replies

  •  

    It sounds as if your program is working because there is almost always something going on with all the other processes.

    One thing to be aware of is that if you are using timers, they almost significant inaccuracies. There are several ways to get around this. The API has high precision timer or you can use the the performance monitor class to get high precision clock ticks. Do not assume that a timer interval is overly meaningful. User a timer to tell you when to get the actual system time.

    Monday, October 22, 2007 11:38 AM
  • Use the stopwatch to do the timing.  Time a loop multiple times(at least 10) and get the mean and standard deviation.  If a time is more than 3 standard deviations from the mean, suspect the timing.  If you program uses a single tread, the times on your example computers would propably be about the same.  The dual core processor has more overhead coordinating the cores and, since it is probably in a later computer, has more processes running on it.

    Monday, October 22, 2007 1:23 PM
  • There is an example for how to know what the speed of the computer processor from VB2005?

    and to know how much percentage are in use on this processor?

     

    Or example of how to do an accurate computer test performance?

     

    Yaniv

     

    Monday, October 22, 2007 3:31 PM
  • Hi Yaniv,

     

    The PerformanceCounter control can be used to count CPU usage.

     

    Prerequisites: PerformanceCounter1,Timer1, ProgressBar1 and Label1 on Form1.

    Code Block

    Imports Microsoft.VisualBasic

    Imports System

    Imports System.Collections.Generic

    Imports System.ComponentModel

    Imports System.Data

    Imports System.Drawing

    Imports System.Text

    Imports System.Windows.Forms

     

    Namespace CpuUsageTest

              Public Partial Class frmCpuUsage

                       Inherits Form

     

            Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

                timer1.Enabled = True

                performanceCounter1.CategoryName = "Processor"

                performanceCounter1.CounterName = "% Processor Time"

                performanceCounter1.InstanceName = "_Total"

            End Sub

     

            Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer1.Tick

                progressBar1.Value = CInt(Fix(performanceCounter1.NextValue()))

                label1.Text = "CPU Usage: " & progressBar1.Value.ToString() & "%"

            End Sub

     

        End Class

    End Namespace

     

    By the way, the statement can get the CPU count.

    Dim count As Int32 = System.Environment.ProcessorCount

     

    Please check this document for detail.

    Monitor and Display CPU State Information

    This article describes a quick and simple approach to displaying information about the state of the CPU or CPUs on a targeted machine.

     

    Regards,

    Martin

    Thursday, October 25, 2007 9:50 AM
  • You can get CPU speed from Registry like this:

    Code Block

    Imports Microsoft.Win32

    Public Class Form1

     

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

            Dim myReg As RegistryKey = Registry.LocalMachine

            Dim myRegKey As RegistryKey

            Dim myVal As String

            myRegKey = myReg.OpenSubKey("HARDWARE\DESCRIPTION\SYSTEM\CentralProcessor\0")

            myVal = myRegKey.GetValue("~Mhz").ToString

            myRegKey.Close()

            TextBox1.Text = String.Format("CPU Speed {0} M", myVal)

        End Sub

    End Class

     

     

    Thursday, October 25, 2007 10:02 AM
  • Here is what you really want. There is a database to compare your machine and other machines.

     

    http://www.wprime.net/

    Thursday, October 25, 2007 12:22 PM
  •  

    Are you sure that the CPU is whats bottlenecking your program?  

     

    A computer's performance is dependant on hundreds of interrelated factors,  its not a simple isssue to identify performance problems (at least not with the info given)

     

     

     

    Thursday, October 25, 2007 2:34 PM
  • Thanks buddy,
    Monday, November 14, 2011 10:12 AM