5
* --------------------------------------------------------------------------
7
* Pthreads-win32 - POSIX Threads Library for Win32
8
* Copyright(C) 1998 John E. Bossom
9
* Copyright(C) 1999,2005 Pthreads-win32 contributors
11
* Contact Email: rpj@callisto.canberra.edu.au
13
* The current list of contributors is contained
14
* in the file CONTRIBUTORS included with the source
15
* code distribution. The list can also be seen at the
16
* following World Wide Web location:
17
* http://sources.redhat.com/pthreads-win32/contributors.html
19
* This library is free software; you can redistribute it and/or
20
* modify it under the terms of the GNU Lesser General Public
21
* License as published by the Free Software Foundation; either
22
* version 2 of the License, or (at your option) any later version.
24
* This library is distributed in the hope that it will be useful,
25
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
* Lesser General Public License for more details.
29
* You should have received a copy of the GNU Lesser General Public
30
* License along with this library in the file COPYING.LIB;
31
* if not, write to the Free Software Foundation, Inc.,
32
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
34
* --------------------------------------------------------------------------
36
* Measure time taken to complete an elementary operation.
39
* Single thread iteration over trylock/unlock for each mutex type.
43
#include <sys/timeb.h>
49
#include "benchtest.h"
51
#define PTW32_MUTEX_TYPES
52
#define ITERATIONS 10000000L
56
pthread_mutexattr_t ma;
57
struct _timeb currSysTimeStart;
58
struct _timeb currSysTimeStop;
59
long durationMilliSecs;
60
long overHeadMilliSecs = 0;
62
#define GetDurationMilliSecs(_TStart, _TStop) ((_TStop.time*1000+_TStop.millitm) \
63
- (_TStart.time*1000+_TStart.millitm))
66
* Dummy use of j, otherwise the loop may be removed by the optimiser
67
* when doing the overhead timing with an empty loop.
70
{ int i, j = 0, k = 0; _ftime(&currSysTimeStart); for (i = 0; i < ITERATIONS; i++) { j++;
73
}; _ftime(&currSysTimeStop); if (j + k == i) j++; }
77
oldRunTest (char * testNameString, int mType)
83
runTest (char * testNameString, int mType)
85
#ifdef PTW32_MUTEX_TYPES
86
pthread_mutexattr_settype(&ma, mType);
88
pthread_mutex_init(&mx, &ma);
91
(void) pthread_mutex_trylock(&mx);
92
(void) pthread_mutex_unlock(&mx);
95
pthread_mutex_destroy(&mx);
97
durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
99
printf( "%-45s %15ld %15.3f\n",
102
(float) durationMilliSecs * 1E3 / ITERATIONS);
107
main (int argc, char *argv[])
109
pthread_mutexattr_init(&ma);
111
printf( "=============================================================================\n");
112
printf( "Trylock plus unlock on an unlocked mutex.\n");
113
printf( "%ld iterations.\n\n", ITERATIONS);
114
printf( "%-45s %15s %15s\n",
118
printf( "-----------------------------------------------------------------------------\n");
121
* Time the loop overhead so we can subtract it from the actual test times.
127
durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
128
overHeadMilliSecs = durationMilliSecs;
130
old_mutex_use = OLD_WIN32CS;
131
assert(old_mutex_init(&ox, NULL) == 0);
133
(void) old_mutex_trylock(&ox);
134
(void) old_mutex_unlock(&ox);
136
assert(old_mutex_destroy(&ox) == 0);
137
durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
138
printf( "%-45s %15ld %15.3f\n",
139
"Old PT Mutex using a Critical Section (WNT)",
141
(float) durationMilliSecs * 1E3 / ITERATIONS);
143
old_mutex_use = OLD_WIN32MUTEX;
144
assert(old_mutex_init(&ox, NULL) == 0);
146
(void) old_mutex_trylock(&ox);
147
(void) old_mutex_unlock(&ox);
149
assert(old_mutex_destroy(&ox) == 0);
150
durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
151
printf( "%-45s %15ld %15.3f\n",
152
"Old PT Mutex using a Win32 Mutex (W9x)",
154
(float) durationMilliSecs * 1E3 / ITERATIONS);
156
printf( ".............................................................................\n");
159
* Now we can start the actual tests
161
#ifdef PTW32_MUTEX_TYPES
162
runTest("PTHREAD_MUTEX_DEFAULT (W9x,WNT)", PTHREAD_MUTEX_DEFAULT);
164
runTest("PTHREAD_MUTEX_NORMAL (W9x,WNT)", PTHREAD_MUTEX_NORMAL);
166
runTest("PTHREAD_MUTEX_ERRORCHECK (W9x,WNT)", PTHREAD_MUTEX_ERRORCHECK);
168
runTest("PTHREAD_MUTEX_RECURSIVE (W9x,WNT)", PTHREAD_MUTEX_RECURSIVE);
170
runTest("Non-blocking lock", 0);
173
printf( "=============================================================================\n");
179
pthread_mutexattr_destroy(&ma);