Results 1 to 9 of 9

Thread: How to test the performance of your code?

  1. #1

    How to test the performance of your code?

    Hey PGD-friends,

    I have a piece of code here which I want to test. I'm not sure how though.

    I have the impression that QueryPerformanceCounter() is a bit unstable (Because of the CPU stepping times that change). GetTickCount() on the other hand is not accurate enough.
    I have an important piece of code for my game, which is going to be called multiple times a frame. So the execution time must be well under 1ms. Also, I want to make some alterations to the algorithm and see if it improves it's performance.

    Any ideas how to do some reliable tests?

    Thanks
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524

    Re: How to test the performance of your code?

    I'm a business analyst by trade and I say increase your sample space.

    That is, measure iterations over a longer period of time and either track CPU usage along with that time (allows you to pick a sample space with the minimum of CPU usage spikes) or do your best to ensure the thread is not interrupted excessively by the OS. (set the thread to real-time priority if you must)

    Then, count the loops performed in say, 30 seconds then finally divide it down so you know the average processing time in MS for a single pass.

    That average will become increasingly more accurate the more time you sample, as long as you've taken care to avoid excessive thread interruption, you'll find that figure to be suitable for your purposes.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  3. #3

    Re: How to test the performance of your code?

    I don't know anything better than QueryPerformanceCounter
    From brazil (:

    Pascal pownz!

  4. #4

    Re: How to test the performance of your code?

    Where do you got the information about QueryPerformanceCounter being unstable?

    To my knowledge QueryPerformanceCounter increases one each cpu cycle and QueryPerformanceFrequency usually returns you're cpu clock speed.

    This should, afaik be very accurate as it gets as the cpu cycle is determined my some kind of quartz crystal witch has a very well defined oscillation time. I could be wrong through
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  5. #5

    Re: How to test the performance of your code?

    I vaguely recall an article on QueryPerformanceCounter. And you are right about the frequency. If you keep updating that too, it "should" work correctly. There might be other reasons to "not use it", but I have to dig up that article.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  6. #6
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2

    Re: How to test the performance of your code?

    If you want to get a bit deeper, you could invest in a code profiler like ProDelphi. I've used this quite a bit to optimise my web server software.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  7. #7

    Re: How to test the performance of your code?

    The free alternative is using FPC and more or less easily profiling your application using valgrind.

  8. #8

    Re: How to test the performance of your code?

    I've had some pretty good luck with http://wiki.lazarus.freepascal.org/EpikTimer and using its sampling routines. Granted its a bit out of date (2006) but still works like a charm.

    - Jeremy

  9. #9

    Re: How to test the performance of your code?

    There is always the free Delphi profiler here:

    http://delphitools.info/samplingprofiler/

    cheers,
    Paul

Bookmarks

Posting Permissions

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