michael@0: /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "vprof.h" michael@0: michael@0: static void cProbe (void* vprofID) michael@0: { michael@0: if (_VAL == _IVAR1) _I64VAR1 ++; michael@0: _IVAR1 = _IVAR0; michael@0: michael@0: if (_VAL == _IVAR0) _I64VAR0 ++; michael@0: _IVAR0 = (int) _VAL; michael@0: michael@0: _DVAR0 = ((double)_I64VAR0) / _COUNT; michael@0: _DVAR1 = ((double)_I64VAR1) / _COUNT; michael@0: } michael@0: michael@0: //__declspec (thread) boolean cv; michael@0: //#define if(c) cv = (c); _vprof (cv); if (cv) michael@0: //#define if(c) cv = (c); _vprof (cv, cProbe); if (cv) michael@0: michael@0: #define THREADS 1 michael@0: #define COUNT 100000 michael@0: #define SLEEPTIME 0 michael@0: michael@0: static int64_t evens = 0; michael@0: static int64_t odds = 0; michael@0: michael@0: void sub(int val) michael@0: { michael@0: int i; michael@0: //_vprof (1); michael@0: for (i = 0; i < COUNT; i++) { michael@0: //_nvprof ("Iteration", 1); michael@0: //_nvprof ("Iteration", 1); michael@0: _vprof (i); michael@0: //_vprof (i); michael@0: //_hprof(i, 3, (int64_t) 1000, (int64_t)2000, (int64_t)3000); michael@0: //_hprof(i, 3, 10000, 10001, 3000000); michael@0: //_nhprof("Event", i, 3, 10000, 10001, 3000000); michael@0: //_nhprof("Event", i, 3, 10000, 10001, 3000000); michael@0: //Sleep(SLEEPTIME); michael@0: if (i % 2 == 0) { michael@0: //_vprof (i); michael@0: ////_hprof(i, 3, 10000, 10001, 3000000); michael@0: //_nvprof ("Iteration", i); michael@0: evens ++; michael@0: } else { michael@0: //_vprof (1); michael@0: _vprof (i, cProbe); michael@0: odds ++; michael@0: } michael@0: //_nvprof ("Iterate", 1); michael@0: } michael@0: //printf("sub %d done.\n", val); michael@0: } michael@0: michael@0: HANDLE array[THREADS]; michael@0: michael@0: static int run (void) michael@0: { michael@0: int i; michael@0: michael@0: time_t start_time = time(0); michael@0: michael@0: for (i = 0; i < THREADS; i++) { michael@0: array[i] = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)sub, (LPVOID)i, 0, 0); michael@0: } michael@0: michael@0: for (i = 0; i < THREADS; i++) { michael@0: WaitForSingleObject(array[i], INFINITE); michael@0: } michael@0: michael@0: return 0; michael@0: } michael@0: michael@0: int main () michael@0: { michael@0: DWORD start, end; michael@0: michael@0: start = GetTickCount (); michael@0: run (); michael@0: end = GetTickCount (); michael@0: michael@0: printf ("\nRun took %d msecs\n\n", end-start); michael@0: }