source: branches/libc-0.6/src/emx/testcase/benchmarks/PrfTiming.h

Last change on this file was 801, checked in by bird, 22 years ago

It's a start...

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: PrfTiming.h 801 2003-10-04 17:42:15Z bird $
2 *
3 * Common timing code.
4 *
5 * Copyright (c) 2001-2003 knut st. osmundsen (bird@anduin.net)
6 *
7 * GPL
8 *
9 */
10
11#include <stdio.h>
12#if !defined(__WINNT__)
13#include <sys/time.h>
14#endif
15#ifndef __NOTPC__
16#include <process.h>
17#endif
18
19#ifdef __OS2__
20#define INCL_BASE
21#define INCL_DOSPROFILE
22#include <os2.h>
23
24long double gettime(void)
25{
26 QWORD qw;
27 DosTmrQueryTime(&qw);
28 return (long double)qw.ulHi * (4294967296.00) + qw.ulLo;
29}
30
31unsigned getHz(void)
32{
33 ULONG ul = -1;
34 DosTmrQueryFreq(&ul);
35 return ul;
36}
37
38void printSystemInfo(void)
39{
40}
41
42#elif defined(__WINNT__)
43#include <windows.h>
44/*
45 * Windows
46 */
47unsigned long __stdcall GetTickCount(void);
48
49long double gettime(void)
50{
51 //return (long double)GetTickCount();
52 LARGE_INTEGER ullCounter;
53 ullCounter.QuadPart = 0;
54 QueryPerformanceCounter(&ullCounter);
55 return (long double)ullCounter.QuadPart;
56}
57
58unsigned getHz(void)
59{
60 //return 1000;
61 LARGE_INTEGER ullFrequency;
62 ullFrequency.QuadPart = 0;
63 QueryPerformanceFrequency(&ullFrequency);
64 return (unsigned)ullFrequency.QuadPart;
65}
66
67void printSystemInfo(void)
68{
69 LONG lrc;
70 SYSTEM_INFO si;
71 HKEY hProcessor0;
72 char szMhz[16];
73 szMhz[0] = '\0';
74
75 lrc = RegOpenKey(HKEY_LOCAL_MACHINE,
76 "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
77 &hProcessor0);
78 if (!lrc)
79 {
80 LONG cchMhz = sizeof(szMhz);
81 DWORD iKey;
82 CHAR szValueName[256];
83 DWORD cchValueName = sizeof(szValueName);
84 DWORD dwType;
85 BYTE abData[256];
86 DWORD cbData;
87
88 iKey = 0;
89 szMhz[0] = '\0';
90 while ((lrc = RegEnumValue(hProcessor0,
91 iKey,
92 szValueName,
93 &cchValueName,
94 NULL,
95 &dwType,
96 &abData,
97 &cbData)) == 0
98 || lrc == ERROR_MORE_DATA)
99 {
100 switch (dwType)
101 {
102 case REG_SZ:
103 case REG_EXPAND_SZ:
104 /*
105 printf("%-24s = type: %1x namesize: %2d data size: %3d bytes\n %s\n",
106 szValueName, dwType, cchValueName, cbData, &abData[0]);
107 */
108 break;
109
110 default:
111 {
112 /*
113 int i,j;
114 printf("%-24s = type: %1x namesize: %2d data size: %3d bytes\n",
115 szValueName, dwType, cchValueName, cbData);
116 for (i = 0; i < cbData; i += 16)
117 {
118 printf(" %04x ", i);
119 for (j = 0; j < 16; j++)
120 {
121 if (j + i < cbData)
122 printf(j == 8 ? "- %02x " : "%02x ",
123 (BYTE)abData[i+j]);
124 else
125 printf(j == 8 ? " " : " ");
126 }
127 putc(' ', stdout);
128 for (j = 0; j < 16; j++)
129 {
130 if (j+i < cbData)
131 putc(isprint(abData[j]) ? abData[j] : '.', stdout);
132 else
133 putc(' ', stdout);
134 }
135 putc('\n', stdout);
136 }
137 */
138 if ( !szMhz[0]
139 && stricmp(szValueName, "~MHz") == 0
140 && dwType == REG_DWORD
141 && cbData == sizeof(DWORD))
142 sprintf(szMhz, "%d", *(PDWORD)&abData[0]);
143 }
144 }
145
146 /* next */
147 iKey++;
148 dwType = 0;
149 cchValueName = sizeof(szValueName);
150 szValueName[0] = '\0';
151 }
152 RegCloseKey(hProcessor0);
153 }
154
155 GetSystemInfo(&si);
156 printf(" %d %d CPUs %s Mhz\n",
157 si.dwNumberOfProcessors,
158 si.dwProcessorType,
159 szMhz
160 );
161}
162
163#else
164
165long double gettime(void)
166{
167 struct timeval tp;
168 long sec = 0L;
169
170 if (gettimeofday(&tp, NULL))
171 return -1;
172 return tp.tv_usec / 1000000.00 + tp.tv_sec;
173}
174
175unsigned getHz(void)
176{
177 return 1;//000000;
178}
179
180void printSystemInfo(void)
181{
182}
183
184#endif
185
Note: See TracBrowser for help on using the repository browser.