|
1 /* -*- Mode: C++; c-basic-offset: 4; 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 { |
|
14 if (_VAL == _IVAR1) _I64VAR1 ++; |
|
15 _IVAR1 = _IVAR0; |
|
16 |
|
17 if (_VAL == _IVAR0) _I64VAR0 ++; |
|
18 _IVAR0 = (int) _VAL; |
|
19 |
|
20 _DVAR0 = ((double)_I64VAR0) / _COUNT; |
|
21 _DVAR1 = ((double)_I64VAR1) / _COUNT; |
|
22 } |
|
23 |
|
24 //__declspec (thread) boolean cv; |
|
25 //#define if(c) cv = (c); _vprof (cv); if (cv) |
|
26 //#define if(c) cv = (c); _vprof (cv, cProbe); if (cv) |
|
27 |
|
28 #define THREADS 1 |
|
29 #define COUNT 100000 |
|
30 #define SLEEPTIME 0 |
|
31 |
|
32 static int64_t evens = 0; |
|
33 static int64_t odds = 0; |
|
34 |
|
35 void sub(int val) |
|
36 { |
|
37 int i; |
|
38 //_vprof (1); |
|
39 for (i = 0; i < COUNT; i++) { |
|
40 //_nvprof ("Iteration", 1); |
|
41 //_nvprof ("Iteration", 1); |
|
42 _vprof (i); |
|
43 //_vprof (i); |
|
44 //_hprof(i, 3, (int64_t) 1000, (int64_t)2000, (int64_t)3000); |
|
45 //_hprof(i, 3, 10000, 10001, 3000000); |
|
46 //_nhprof("Event", i, 3, 10000, 10001, 3000000); |
|
47 //_nhprof("Event", i, 3, 10000, 10001, 3000000); |
|
48 //Sleep(SLEEPTIME); |
|
49 if (i % 2 == 0) { |
|
50 //_vprof (i); |
|
51 ////_hprof(i, 3, 10000, 10001, 3000000); |
|
52 //_nvprof ("Iteration", i); |
|
53 evens ++; |
|
54 } else { |
|
55 //_vprof (1); |
|
56 _vprof (i, cProbe); |
|
57 odds ++; |
|
58 } |
|
59 //_nvprof ("Iterate", 1); |
|
60 } |
|
61 //printf("sub %d done.\n", val); |
|
62 } |
|
63 |
|
64 HANDLE array[THREADS]; |
|
65 |
|
66 static int run (void) |
|
67 { |
|
68 int i; |
|
69 |
|
70 time_t start_time = time(0); |
|
71 |
|
72 for (i = 0; i < THREADS; i++) { |
|
73 array[i] = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)sub, (LPVOID)i, 0, 0); |
|
74 } |
|
75 |
|
76 for (i = 0; i < THREADS; i++) { |
|
77 WaitForSingleObject(array[i], INFINITE); |
|
78 } |
|
79 |
|
80 return 0; |
|
81 } |
|
82 |
|
83 int main () |
|
84 { |
|
85 DWORD start, end; |
|
86 |
|
87 start = GetTickCount (); |
|
88 run (); |
|
89 end = GetTickCount (); |
|
90 |
|
91 printf ("\nRun took %d msecs\n\n", end-start); |
|
92 } |