Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

344 lines
9.2 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1994 - 1999
  3. Module Name:
  4. local.c
  5. Abstract:
  6. RPC performance to measure system/processor/memory overhead.
  7. memcpy, string operations, memory allocation, kernel traps
  8. Author:
  9. Mario Goertzel (mariogo) 30-Mar-1994
  10. Revision History:
  11. --*/
  12. #include<rpcperf.h>
  13. #define REGISTRY_ROOT_KEY HKEY_LOCAL_MACHINE
  14. static char * RPC_UUID_PERSISTENT_DATA="Software\\Description\\Microsoft\\Rpc\\3.1\\RpcUuidPersistentData";
  15. static char * PREV_CLOCK_SEQUENCE="PreviousClockSequence";
  16. static char * PREV_TIME_ALLOCATED="PreviousTimeAllocated";
  17. const char *USAGE="-n case -i iterations\n"
  18. " -n 1 - Memory copy\n"
  19. " -n 2 - String copy\n"
  20. " -n 3 - String length\n"
  21. " -n 4 - Allocate/free memory\n"
  22. " -n 5 - Kernel traps (set and reset event)\n"
  23. " -n 6 - GetTickCount\n"
  24. " -n 7 - Open & Query Registry\n"
  25. " -n 8 - Query Registry\n"
  26. " -n 9 - Open & Update Registry\n"
  27. " -n 10 - Update Registry\n";
  28. int __cdecl
  29. main(int argc, char **argv)
  30. {
  31. unsigned int i;
  32. int size;
  33. unsigned long seconds, mseconds;
  34. char *buffer;
  35. char *buffer2;
  36. HANDLE event;
  37. HANDLE heap;
  38. long status;
  39. ParseArgv(argc, argv);
  40. if (Options[0] == -1)
  41. {
  42. puts(USAGE);
  43. exit(1);
  44. }
  45. if (Options[0] < 4 && Options[0] > 0)
  46. {
  47. if ((Options[1] < 0) || (Options[2] < 0) || (Options[2] < Options[1]))
  48. {
  49. printf("Case %d requires -n start -n end_size switches\n",
  50. Options[0]);
  51. exit(1);
  52. }
  53. buffer = RtlAllocateHeap(RtlProcessHeap(),0,Options[2]);
  54. buffer2 = RtlAllocateHeap(RtlProcessHeap(),0,Options[2]);
  55. // For string tests
  56. for(i = 0; i < (unsigned long)Options[1]; i++)
  57. buffer[i] = 'M';
  58. printf("Start size, end size: %d, %d\n", Options[1], Options[2]);
  59. }
  60. switch (Options[0])
  61. {
  62. case 1:
  63. // Memory copy test
  64. size = Options[1];
  65. while(size < Options[2])
  66. {
  67. printf("Size: % 6d : ", size);
  68. StartTime();
  69. for(i = 0; i < Iterations; i++)
  70. memcpy(buffer,buffer2,size);
  71. EndTime("for memcpy");
  72. size *= 2;
  73. }
  74. break;
  75. case 2:
  76. // String copy test
  77. size = Options[1];
  78. while(size < Options[2])
  79. {
  80. printf("Lenght: % 6d : ", size);
  81. for(i = 0; i < (unsigned long)size-1; i++)
  82. buffer[i] = 'A';
  83. buffer[size-1] = '\0';
  84. StartTime();
  85. for(i = 0; i < Iterations; i++)
  86. strcpy(buffer2, buffer);
  87. EndTime("for strcpy");
  88. size *= 2;
  89. }
  90. break;
  91. case 3:
  92. // String len test
  93. size = Options[1];
  94. while(size < Options[2])
  95. {
  96. printf("Lenght: % 6d : ", size);
  97. for(i = 0; i < (unsigned long)size-1; i++)
  98. buffer[i] = 'A';
  99. buffer[size-1] = '\0';
  100. StartTime();
  101. for(i = 0; i < Iterations; i++)
  102. strlen(buffer);
  103. EndTime("for strlen");
  104. size *= 2;
  105. }
  106. break;
  107. case 4:
  108. // Allocate/Free tests
  109. if (Options[1] == -1)
  110. {
  111. printf("Memory test requires an addition -n switch for block size\n");
  112. exit(1);
  113. }
  114. printf("Block size: %d\n", Options[1]);
  115. heap = RtlProcessHeap();
  116. StartTime();
  117. for(i = 0; i < Iterations; i++)
  118. {
  119. buffer = RtlAllocateHeap(heap,0,Options[1]);
  120. RtlFreeHeap(heap, 0, buffer);
  121. }
  122. EndTime("for Rtl{Alloc,Free}Heap");
  123. StartTime();
  124. for(i = 0; i < Iterations; i++)
  125. {
  126. buffer = malloc(Options[1]);
  127. free(buffer);
  128. }
  129. EndTime("for Malloc/Free");
  130. StartTime();
  131. for(i = 0; i < Iterations; i++)
  132. {
  133. buffer = LocalAlloc(0, Options[1]);
  134. LocalFree(buffer);
  135. }
  136. EndTime("for Local{Alloc/Free} (0)");
  137. StartTime();
  138. for(i = 0; i < Iterations; i++)
  139. {
  140. buffer = LocalAlloc(LPTR, Options[1]);
  141. LocalFree(buffer);
  142. }
  143. EndTime("for Local{Alloc/Free} (LPTR)");
  144. break;
  145. case 5:
  146. // Kernel traps
  147. event = CreateEvent(0, FALSE, FALSE, 0);
  148. CHECK_STATUS(event == 0, "CreateEvent");
  149. StartTime();
  150. for(i = 0; i < Iterations; i++)
  151. SetEvent(event);
  152. EndTime("for SetEvent");
  153. StartTime();
  154. for(i = 0; i < Iterations; i++)
  155. ResetEvent(event);
  156. EndTime("for ResetEvent");
  157. break;
  158. case 6:
  159. // GetTickCount
  160. StartTime();
  161. for(i = 0; i < Iterations; i++)
  162. GetTickCount();
  163. EndTime("for GetTickCount");
  164. break;
  165. case 7:
  166. {
  167. // Open and Query Registry
  168. HKEY Key;
  169. DWORD BufLen = 30;
  170. char String[30];
  171. StartTime();
  172. for (i = 0; i < Iterations; i++)
  173. {
  174. status =
  175. RegOpenKey(REGISTRY_ROOT_KEY,
  176. RPC_UUID_PERSISTENT_DATA,
  177. &Key);
  178. if (status)
  179. printf("RegOpenKey returned %d\n", status);
  180. status =
  181. RegQueryValue(Key,
  182. PREV_CLOCK_SEQUENCE,
  183. String,
  184. &BufLen);
  185. if (status)
  186. printf("RegQueryValue returned %d\n", status);
  187. RegCloseKey(Key);
  188. }
  189. EndTime("for opening and querying a registry key");
  190. }
  191. break;
  192. case 8:
  193. {
  194. // Query Registry
  195. HKEY Key;
  196. DWORD BufLen = 30;
  197. char String[30];
  198. status =
  199. RegOpenKey(REGISTRY_ROOT_KEY,
  200. RPC_UUID_PERSISTENT_DATA,
  201. &Key);
  202. if (status)
  203. printf("RegOpenKey returned %d\n", status);
  204. StartTime();
  205. for (i = 0; i < Iterations; i++)
  206. {
  207. status =
  208. RegQueryValue(Key,
  209. PREV_CLOCK_SEQUENCE,
  210. String,
  211. &BufLen);
  212. if (status)
  213. printf("RegQueryValue returned %d\n", status);
  214. }
  215. EndTime("for querying a registry key");
  216. RegCloseKey(Key);
  217. }
  218. break;
  219. case 9:
  220. {
  221. // Create and update.
  222. HKEY Key;
  223. DWORD BufLen;
  224. static const char String[] = "24682468";
  225. StartTime();
  226. for (i = 0; i < Iterations; i++)
  227. {
  228. status =
  229. RegCreateKey(REGISTRY_ROOT_KEY,
  230. RPC_UUID_PERSISTENT_DATA,
  231. &Key);
  232. if (status)
  233. printf("RegOpenKey returned %d\n", status);
  234. status =
  235. RegSetValue(Key,
  236. PREV_CLOCK_SEQUENCE,
  237. REG_SZ,
  238. String,
  239. strlen(String)+1);
  240. if (status)
  241. printf("RegSetValue returned %d\n", status);
  242. RegCloseKey(Key);
  243. }
  244. EndTime("for creating and updateing a registry key.");
  245. }
  246. break;
  247. case 10:
  248. {
  249. // Update Registry
  250. HKEY Key;
  251. DWORD BufLen;
  252. static const char String[] = "24682468";
  253. status =
  254. RegCreateKey(REGISTRY_ROOT_KEY,
  255. RPC_UUID_PERSISTENT_DATA,
  256. &Key);
  257. if (status)
  258. printf("RegOpenKey returned %d\n", status);
  259. StartTime();
  260. for (i = 0; i < Iterations; i++)
  261. {
  262. status =
  263. RegSetValue(Key,
  264. PREV_CLOCK_SEQUENCE,
  265. REG_SZ,
  266. String,
  267. strlen(String)+1);
  268. if (status)
  269. printf("RegSetValue returned %d\n", status);
  270. }
  271. EndTime("for updating a registry key.");
  272. RegCloseKey(Key);
  273. }
  274. break;
  275. }
  276. return 0;
  277. }