tin  2.6.1
About: TIN is a threaded NNTP and spool based UseNet newsreader.
  Fossies Dox: tin-2.6.1.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

stpwatch.h
Go to the documentation of this file.
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-2022 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
50char msg_tb[LEN];
51char tmp_tb[LEN];
52struct timeb beg_tb;
53struct timeb end_tb;
54
55# define LSECS 700000000 /* offset to keep numbers smaller (1992-03-07 20:26:40 UTC) */
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] Elap=[%ld ms]", \
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
73char msg_tb[LEN];
74char tmp_tb[LEN];
75float d_time;
76struct timeval beg_tb, end_tb;
77
78# define BegStopWatch(msg) {strcpy (msg_tb, msg); \
79 (void) gettimeofday (&beg_tb, NULL);}
80
81# define EndStopWatch() {(void) gettimeofday (&end_tb, NULL); \
82 if ((end_tb.tv_usec -= beg_tb.tv_usec) < 0) { \
83 end_tb.tv_sec--; \
84 end_tb.tv_usec += 1000000; \
85 } \
86 end_tb.tv_sec -= beg_tb.tv_sec; \
87 d_time = (end_tb.tv_sec * 1000.0 + ((float) end_tb.tv_usec) / 1000.0);}
88
89# define PrintStopWatch() {sprintf (tmp_tb, "StopWatch(%s): %6.3f ms", msg_tb, d_time); \
90 error_message(2, tmp_tb);}
91
92# endif /* HAVE_SYS_TIME_H */
93# endif /* HAVE_SYS_TIMEB_H && HAVE_FTIME */
94
95# else /* PROFILE */
96
97# define BegStopWatch(msg)
98# define EndStopWatch()
99# define PrintStopWatch()
100
101# endif /* PROFILE */
102#endif /* !STPWATCH_H */
#define LEN
Definition: tin.h:860