in reply to Timer implementation

What is the application? What time resolution do you need? What is the code you have tried?


Perl reduces RSI - it saves typing

Replies are listed 'Best First'.
Re^2: Timer implementation
by bash (Scribe) on Sep 16, 2008 at 02:20 UTC
    My application is cgi script. I need at least milli-second. My code is very simple. At case of times(). I use:
    $start = [times()]; ...somecode... $end = [times()]; $time_diff =($start->[0] + $start->[1]) - ($end->[0] + $end->[1]);
    at case of Time::HiRes
    $start=[gettimeofday]; ...somecode... $end = [gettimeofday]; $time_diff = tv_interval($start, $end);
    But if real <=> sys+user, my first case will be always lower that at case 2

      Your implementation context is CGI script, but that is not your application. Your application may be timing a database query or some such. So, what is the application?

      You need to decide what it is that you want to report - wall clock time or process time.

      With most operating systems that are not designed for real time environments reporting wall clock times of less than a few milliseconds is fairly meaningless because time slices for tasks are of that order and will render any real time reporting at that level meaningless.


      Perl reduces RSI - it saves typing
        My application is CGI script that works with SQLite and does a lot of text manipulation works.
        Of course i need wall clock to know is it my script works so slowly or it is slow network throughput.
        If script works slowly, then i will know that i need to do some code optimization.
        But if i got situation where real time is much more bigger than sys+real time. What to do in this case? And is it possible case? If I understand correctly it's possible at case where CPU is busy by other process or my process is sleeping on I/O system calls. If it's true - robust timer should include all three number - real, system and user times. Am i right?