testVprofMT.c (2001B)
1 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 4 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include <windows.h> 7 #include <stdio.h> 8 #include <time.h> 9 10 #include "vprof.h" 11 12 static void cProbe(void* vprofID) { 13 if (_VAL == _IVAR1) _I64VAR1++; 14 _IVAR1 = _IVAR0; 15 16 if (_VAL == _IVAR0) _I64VAR0++; 17 _IVAR0 = (int)_VAL; 18 19 _DVAR0 = ((double)_I64VAR0) / _COUNT; 20 _DVAR1 = ((double)_I64VAR1) / _COUNT; 21 } 22 23 //__declspec (thread) boolean cv; 24 // #define if(c) cv = (c); _vprof (cv); if (cv) 25 // #define if(c) cv = (c); _vprof (cv, cProbe); if (cv) 26 27 #define THREADS 1 28 #define COUNT 100000 29 #define SLEEPTIME 0 30 31 static int64_t evens = 0; 32 static int64_t odds = 0; 33 34 void sub(int val) { 35 int i; 36 //_vprof (1); 37 for (i = 0; i < COUNT; i++) { 38 //_nvprof ("Iteration", 1); 39 //_nvprof ("Iteration", 1); 40 _vprof(i); 41 //_vprof (i); 42 //_hprof(i, 3, (int64_t) 1000, (int64_t)2000, (int64_t)3000); 43 //_hprof(i, 3, 10000, 10001, 3000000); 44 //_nhprof("Event", i, 3, 10000, 10001, 3000000); 45 //_nhprof("Event", i, 3, 10000, 10001, 3000000); 46 // Sleep(SLEEPTIME); 47 if (i % 2 == 0) { 48 //_vprof (i); 49 ////_hprof(i, 3, 10000, 10001, 3000000); 50 //_nvprof ("Iteration", i); 51 evens++; 52 } else { 53 //_vprof (1); 54 _vprof(i, cProbe); 55 odds++; 56 } 57 //_nvprof ("Iterate", 1); 58 } 59 // printf("sub %d done.\n", val); 60 } 61 62 HANDLE array[THREADS]; 63 64 static int run(void) { 65 int i; 66 67 time_t start_time = time(0); 68 69 for (i = 0; i < THREADS; i++) { 70 array[i] = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)sub, (LPVOID)i, 0, 0); 71 } 72 73 for (i = 0; i < THREADS; i++) { 74 WaitForSingleObject(array[i], INFINITE); 75 } 76 77 return 0; 78 } 79 80 int main() { 81 DWORD start, end; 82 83 start = GetTickCount(); 84 run(); 85 end = GetTickCount(); 86 87 printf("\nRun took %d msecs\n\n", end - start); 88 }