CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2001
    Posts
    10

    Getting frequency of processor

    Is there a function in Visual Basic to get the clock frequency of the PC's processor ?
    Any help appreciated.


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Getting frequency of processor

    http://codeguru.com/cgi-bin/bbs/wt/s...age=&view=&sb=
    Clearcode docet

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jun 2001
    Posts
    10

    Re: Getting frequency of processor

    Sorry but this doesn't answer to my question. I'm not interested in getting the occupation of the CPU.


  4. #4
    Join Date
    Jan 2001
    Posts
    165

    Re: Getting frequency of processor


  5. #5
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Getting frequency of processor

    Without 3rd party dlls solution:


    private Declare Function QueryPerformanceFrequency Lib "kernel32.dll" (lpFrequency as Long) as Long

    public property get PerformanceFrequency() as Long

    Dim lRet as Long
    Dim lFrequency as Long

    lRet = QueryPerformanceFrequency(lFrequency)
    If Err.LastDllError <> 0 then
    MsgBox "error getting processor frequency"
    else
    PerformanceFrequency = lFrequency
    End If

    End property




    Hope this helps,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Getting frequency of processor

    Only a pity I am out of votes...
    Have a nice day, man.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Getting frequency of processor

    Actually there's a bit more work needed, as I'm passing a VB Long but the API call should return a LARGE_INTEGER so the number might not be right.

    Does the value you get tally with your CPU expectation?

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Getting frequency of processor


    private Type LARGE_INTEGER
    LowPart as Long
    HighPart as Long
    End Type
    private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount as LARGE_INTEGER) as Long
    private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency as LARGE_INTEGER) as Long
    private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination as Any, Source as Any, byval Length as Long)
    private Sub Form_Load()
    'KPD-Team 2001
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    Dim T as Long, liFrequency as LARGE_INTEGER, liStart as LARGE_INTEGER, liStop as LARGE_INTEGER
    Dim cuFrequency as Currency, cuStart as Currency, cuStop as Currency
    'Retrieve the frequency of the performance counter
    If QueryPerformanceFrequency(liFrequency) = 0 then
    MsgBox "Your hardware doesn't support a high-resolution performance counter!", vbInformation
    else
    'convert the large integer to currency
    cuFrequency = LargeIntToCurrency(liFrequency)
    'retrieve tick count
    QueryPerformanceCounter liStart
    'do something
    for T = 0 to 100000
    DoEvents
    next T
    'retrieve tick count
    QueryPerformanceCounter liStop
    'convert large integers to currency's
    cuStart = LargeIntToCurrency(liStart)
    cuStop = LargeIntToCurrency(liStop)
    'calculate how many seconds passed, and show the result
    MsgBox "time: " + CStr((cuStop - cuStart) / cuFrequency) + " seconds"
    End If
    End Sub
    private Function LargeIntToCurrency(liInput as LARGE_INTEGER) as Currency
    'copy 8 bytes from the large integer to an ampty currency
    CopyMemory LargeIntToCurrency, liInput, LenB(liInput)
    'adjust it
    LargeIntToCurrency = LargeIntToCurrency * 10000
    End Function




    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured