"Fossies" - the Fresh Open Source Software Archive

Member "tin-2.4.4/include/stpwatch.h" (20 Nov 2019, 3479 Bytes) of package /linux/misc/tin-2.4.4.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "stpwatch.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.4.3_vs_2.4.4.

    1 /*
    2  *  Project   : tin - a Usenet reader
    3  *  Module    : stpwatch.h
    4  *  Author    : I. Lea
    5  *  Created   : 1993-08-03
    6  *  Updated   : 2008-11-22
    7  *  Notes     : Simple stopwatch routines for timing code using timeb
    8  *               or gettimeofday structs
    9  *
   10  * Copyright (c) 1993-2020 Iain Lea <iain@bricbrac.de>
   11  * All rights reserved.
   12  *
   13  * Redistribution and use in source and binary forms, with or without
   14  * modification, are permitted provided that the following conditions
   15  * are met:
   16  *
   17  * 1. Redistributions of source code must retain the above copyright notice,
   18  *    this list of conditions and the following disclaimer.
   19  *
   20  * 2. Redistributions in binary form must reproduce the above copyright
   21  *    notice, this list of conditions and the following disclaimer in the
   22  *    documentation and/or other materials provided with the distribution.
   23  *
   24  * 3. Neither the name of the copyright holder nor the names of its
   25  *    contributors may be used to endorse or promote products derived from
   26  *    this software without specific prior written permission.
   27  *
   28  * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
   32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   38  * POSSIBILITY OF SUCH DAMAGE.
   39  */
   40 
   41 
   42 #ifndef STPWATCH_H
   43 #   define STPWATCH_H 1
   44 
   45 #   ifdef PROFILE
   46 
   47 #       if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
   48 #           include <sys/timeb.h>
   49 
   50 char msg_tb[LEN];
   51 char tmp_tb[LEN];
   52 struct timeb beg_tb;
   53 struct timeb end_tb;
   54 
   55 #           define LSECS 700000000
   56 
   57 #           define BegStopWatch(msg)    {strcpy (msg_tb, msg); ftime (&beg_tb);}
   58 
   59 #           define EndStopWatch()       {ftime (&end_tb);}
   60 
   61 #           define PrintStopWatch() {sprintf (tmp_tb, "%s: Beg=[%ld.%d] End=[%ld.%d] Elapsed=[%ld]", \
   62                  msg_tb, beg_tb.time, beg_tb.millitm, \
   63                  end_tb.time, end_tb.millitm, \
   64                  (((end_tb.time - LSECS) * 1000) + end_tb.millitm) - \
   65                  (((beg_tb.time - LSECS) * 1000) + beg_tb.millitm)); \
   66                  error_message(2, tmp_tb, "");}
   67 
   68 #       else    /* HAVE_SYS_TIMEB_H && HAVE_FTIME */
   69 
   70 #       ifdef   HAVE_SYS_TIME_H
   71 #           include <sys/time.h>
   72 
   73 char msg_tb[LEN], tmp_tb[LEN];
   74 struct timeval beg_tb, end_tb;
   75 float d_time;
   76 
   77 #           define BegStopWatch(msg)    {strcpy (msg_tb, msg); \
   78                  (void) gettimeofday (&beg_tb, NULL);}
   79 
   80 #           define EndStopWatch()       {(void) gettimeofday (&end_tb, NULL); \
   81                 if ((end_tb.tv_usec -= beg_tb.tv_usec) < 0) { \
   82                     end_tb.tv_sec--; \
   83                     end_tb.tv_usec += 1000000; \
   84                  } \
   85                  end_tb.tv_sec -= beg_tb.tv_sec; \
   86                  d_time = (end_tb.tv_sec*1000.0 + ((float)end_tb.tv_usec)/1000.0);}
   87 
   88 #           define PrintStopWatch() {sprintf (tmp_tb, "StopWatch(%s): %6.3f ms", msg_tb, d_time); \
   89                  error_message(2, tmp_tb, "");}
   90 
   91 #       endif /* HAVE_SYS_TIME_H */
   92 #   endif /* HAVE_SYS_TIMEB_H && HAVE_FTIME */
   93 
   94 #   else    /* PROFILE */
   95 
   96 #       define BegStopWatch(msg)
   97 #       define EndStopWatch()
   98 #       define PrintStopWatch()
   99 
  100 #   endif /* PROFILE */
  101 #endif /* !STPWATCH_H */