Re: timing a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>>>> "D Cleveland" == D Cleveland <dc7525@ship.edu> writes:

D Cleveland> Im looking to check the relative time it takes to call a function and then
D Cleveland> return.  does anyone know how i can do this easily?  heres what im hoping
D Cleveland> i can do...

D Cleveland> int len;

D Cleveland> len = check_timer();
D Cleveland> function_to_time();
D Cleveland> len = check_timer() - len;

Can you invoke the function many times in a loop ? If so, you may consider doing:

    start = check_timer ();
    for (i = 0; i < SOME_CONST_EG_10000; i++)
      function_to_time ();
    end = check_timer ();
    function_time = (end - start) / SOME_CONST_EG_10000;

as this will make the timing error <= clock-precision / 10000;

Regards,
-velco
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux