"Fossies" - the Fresh Open Source Software Archive

Member "tin-2.4.1/include/stpwatch.h" (12 Oct 2016, 3377 Bytes) of package /linux/misc/tin-2.4.1.tar.gz:


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.0_vs_2.4.1.

    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-2017 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  * 1. Redistributions of source code must retain the above copyright
   17  *    notice, this list of conditions and the following disclaimer.
   18  * 2. Redistributions in binary form must reproduce the above copyright
   19  *    notice, this list of conditions and the following disclaimer in the
   20  *    documentation and/or other materials provided with the distribution.
   21  * 3. The name of the author may not be used to endorse or promote
   22  *    products derived from this software without specific prior written
   23  *    permission.
   24  *
   25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
   26  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   27  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
   29  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   31  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   36  */
   37 
   38 
   39 #ifndef STPWATCH_H
   40 #   define STPWATCH_H 1
   41 
   42 #   ifdef PROFILE
   43 
   44 #       if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
   45 #           include <sys/timeb.h>
   46 
   47 char msg_tb[LEN];
   48 char tmp_tb[LEN];
   49 struct timeb beg_tb;
   50 struct timeb end_tb;
   51 
   52 #           define LSECS 700000000
   53 
   54 #           define BegStopWatch(msg)    {strcpy (msg_tb, msg); ftime (&beg_tb);}
   55 
   56 #           define EndStopWatch()       {ftime (&end_tb);}
   57 
   58 #           define PrintStopWatch() {sprintf (tmp_tb, "%s: Beg=[%ld.%d] End=[%ld.%d] Elapsed=[%ld]", \
   59                  msg_tb, beg_tb.time, beg_tb.millitm, \
   60                  end_tb.time, end_tb.millitm, \
   61                  (((end_tb.time - LSECS) * 1000) + end_tb.millitm) - \
   62                  (((beg_tb.time - LSECS) * 1000) + beg_tb.millitm)); \
   63                  error_message(2, tmp_tb, "");}
   64 
   65 #       else    /* HAVE_SYS_TIMEB_H && HAVE_FTIME */
   66 
   67 #       ifdef   HAVE_SYS_TIME_H
   68 #           include <sys/time.h>
   69 
   70 char msg_tb[LEN], tmp_tb[LEN];
   71 struct timeval beg_tb, end_tb;
   72 float d_time;
   73 
   74 #           define BegStopWatch(msg)    {strcpy (msg_tb, msg); \
   75                  (void) gettimeofday (&beg_tb, NULL);}
   76 
   77 #           define EndStopWatch()       {(void) gettimeofday (&end_tb, NULL); \
   78                 if ((end_tb.tv_usec -= beg_tb.tv_usec) < 0) { \
   79                     end_tb.tv_sec--; \
   80                     end_tb.tv_usec += 1000000; \
   81                  } \
   82                  end_tb.tv_sec -= beg_tb.tv_sec; \
   83                  d_time = (end_tb.tv_sec*1000.0 + ((float)end_tb.tv_usec)/1000.0);}
   84 
   85 #           define PrintStopWatch() {sprintf (tmp_tb, "StopWatch(%s): %6.3f ms", msg_tb, d_time); \
   86                  error_message(2, tmp_tb, "");}
   87 
   88 #       endif /* HAVE_SYS_TIME_H */
   89 #   endif /* HAVE_SYS_TIMEB_H && HAVE_FTIME */
   90 
   91 #   else    /* PROFILE */
   92 
   93 #       define BegStopWatch(msg)
   94 #       define EndStopWatch()
   95 #       define PrintStopWatch()
   96 
   97 #   endif /* PROFILE */
   98 #endif /* !STPWATCH_H */