Leaked source code of windows server 2003
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.

518 lines
14 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * perftext.cpp
  8. *
  9. * Abstract:
  10. *
  11. * Contains all the tests for any routines that do text functionality.
  12. *
  13. \**************************************************************************/
  14. #include "perftest.h"
  15. WCHAR TestStringW[] = L"The quick brown fox jumps over the lazy dog.";
  16. CHAR TestStringA[] = "The quick brown fox jumps over the lazy dog.";
  17. INT TestString_Count = sizeof(TestStringW) / sizeof(TestStringW[0]) - 1;
  18. float Text_Draw_PerCall_30pt_Aliased(Graphics *g, HDC hdc)
  19. {
  20. UINT iterations;
  21. float seconds;
  22. if (g)
  23. {
  24. FontFamily fontFamily(L"Arial");
  25. Font font(&fontFamily, 30);
  26. StringFormat stringFormat(0);
  27. SolidBrush brush(Color::Red);
  28. PointF origin(0, 0);
  29. StartTimer();
  30. do {
  31. PointF origin(64, 64);
  32. g->DrawString(L"A", 1, &font, origin, &stringFormat, &brush);
  33. } while (!EndTimer());
  34. g->Flush(FlushIntentionSync);
  35. GetTimer(&seconds, &iterations);
  36. }
  37. else
  38. {
  39. HFONT font = CreateFont(30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _T("Arial"));
  40. HGDIOBJ oldFont = SelectObject(hdc, font);
  41. SetTextColor(hdc, RGB(0xff, 0, 0));
  42. SetBkMode(hdc, TRANSPARENT);
  43. StartTimer();
  44. do {
  45. TextOut(hdc, 0, 0, _T("A"), 1);
  46. } while (!EndTimer());
  47. GdiFlush();
  48. GetTimer(&seconds, &iterations);
  49. }
  50. return(iterations / seconds / KILO); // Calls per second
  51. }
  52. float Text_Draw_PerGlyph_30pt_Aliased(Graphics *g, HDC hdc)
  53. {
  54. UINT iterations;
  55. float seconds;
  56. if (g)
  57. {
  58. FontFamily fontFamily(L"Arial");
  59. Font font(&fontFamily, 30);
  60. StringFormat stringFormat(0);
  61. SolidBrush brush(Color::Red);
  62. PointF origin(0, 0);
  63. // Don't count font realization towards per-glyph time:
  64. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  65. StartTimer();
  66. do {
  67. PointF origin(64, 64);
  68. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  69. } while (!EndTimer());
  70. g->Flush(FlushIntentionSync);
  71. GetTimer(&seconds, &iterations);
  72. }
  73. else
  74. {
  75. HFONT font = CreateFont(30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _T("Arial"));
  76. HGDIOBJ oldFont = SelectObject(hdc, font);
  77. SetTextColor(hdc, RGB(0xff, 0, 0));
  78. SetBkMode(hdc, TRANSPARENT);
  79. TextOutA(hdc, 0, 0, TestStringA, TestString_Count);
  80. StartTimer();
  81. do {
  82. TextOutA(hdc, 0, 0, TestStringA, TestString_Count);
  83. } while (!EndTimer());
  84. GdiFlush();
  85. GetTimer(&seconds, &iterations);
  86. }
  87. UINT glyphs = TestString_Count * iterations;
  88. return(glyphs / seconds / KILO); // Kglyphs/s
  89. }
  90. float Text_Draw_PerGlyph_30pt_LinearGradient(Graphics *g, HDC hdc)
  91. {
  92. UINT iterations;
  93. float seconds;
  94. if (!g) return(0); // No GDI equivalent
  95. FontFamily fontFamily(L"Arial");
  96. Font font(&fontFamily, 30);
  97. StringFormat stringFormat(0);
  98. LinearGradientBrush brush(Point(0, 0), Point(512, 512), Color::Red, Color::Blue);
  99. PointF origin(0, 0);
  100. // Don't count font realization towards per-glyph time:
  101. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  102. StartTimer();
  103. do {
  104. PointF origin(64, 64);
  105. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  106. } while (!EndTimer());
  107. g->Flush(FlushIntentionSync);
  108. GetTimer(&seconds, &iterations);
  109. UINT glyphs = TestString_Count * iterations;
  110. return(glyphs / seconds / KILO); // Kglyphs/s
  111. }
  112. float Text_Draw_PerCall_30pt_LinearGradient(Graphics *g, HDC hdc)
  113. {
  114. UINT iterations;
  115. float seconds;
  116. if (!g) return(0); // No GDI equivalent
  117. FontFamily fontFamily(L"Arial");
  118. Font font(&fontFamily, 30);
  119. StringFormat stringFormat(0);
  120. LinearGradientBrush brush(Point(0, 0), Point(512, 512), Color::Red, Color::Blue);
  121. PointF origin(0, 0);
  122. StartTimer();
  123. do {
  124. PointF origin(64, 64);
  125. g->DrawString(L"A", 1, &font, origin, &stringFormat, &brush);
  126. } while (!EndTimer());
  127. g->Flush(FlushIntentionSync);
  128. GetTimer(&seconds, &iterations);
  129. UINT glyphs = TestString_Count * iterations;
  130. return(glyphs / seconds / KILO); // Kglyphs/s
  131. }
  132. float Text_Draw_PerCall_30pt_Antialiased(Graphics *g, HDC hdc)
  133. {
  134. UINT iterations;
  135. float seconds;
  136. if (g)
  137. {
  138. g->SetTextRenderingHint(TextRenderingHintAntiAlias);
  139. FontFamily fontFamily(L"Arial");
  140. Font font(&fontFamily, 30);
  141. StringFormat stringFormat(0);
  142. SolidBrush brush(Color::Red);
  143. PointF origin(0, 0);
  144. StartTimer();
  145. do {
  146. PointF origin(64, 64);
  147. g->DrawString(L"A", 1, &font, origin, &stringFormat, &brush);
  148. } while (!EndTimer());
  149. g->Flush(FlushIntentionSync);
  150. GetTimer(&seconds, &iterations);
  151. }
  152. else
  153. {
  154. HFONT font = CreateFont(30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ANTIALIASED_QUALITY, 0, _T("Arial"));
  155. HGDIOBJ oldFont = SelectObject(hdc, font);
  156. SetTextColor(hdc, RGB(0xff, 0, 0));
  157. SetBkMode(hdc, TRANSPARENT);
  158. StartTimer();
  159. do {
  160. TextOut(hdc, 0, 0, _T("A"), 1);
  161. } while (!EndTimer());
  162. GdiFlush();
  163. GetTimer(&seconds, &iterations);
  164. }
  165. return(iterations / seconds / KILO); // Calls per second
  166. }
  167. float Text_Draw_PerGlyph_30pt_Antialiased(Graphics *g, HDC hdc)
  168. {
  169. UINT iterations;
  170. float seconds;
  171. if (g)
  172. {
  173. g->SetTextRenderingHint(TextRenderingHintAntiAlias);
  174. FontFamily fontFamily(L"Arial");
  175. Font font(&fontFamily, 30);
  176. StringFormat stringFormat(0);
  177. SolidBrush brush(Color::Red);
  178. PointF origin(0, 0);
  179. // Don't count font realization towards per-glyph time:
  180. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  181. StartTimer();
  182. do {
  183. PointF origin(64, 64);
  184. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  185. } while (!EndTimer());
  186. g->Flush(FlushIntentionSync);
  187. GetTimer(&seconds, &iterations);
  188. }
  189. else
  190. {
  191. HFONT font = CreateFont(30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ANTIALIASED_QUALITY, 0, _T("Arial"));
  192. HGDIOBJ oldFont = SelectObject(hdc, font);
  193. SetTextColor(hdc, RGB(0xff, 0, 0));
  194. SetBkMode(hdc, TRANSPARENT);
  195. TextOutA(hdc, 0, 0, TestStringA, TestString_Count);
  196. StartTimer();
  197. do {
  198. TextOutA(hdc, 0, 0, TestStringA, TestString_Count);
  199. } while (!EndTimer());
  200. GdiFlush();
  201. GetTimer(&seconds, &iterations);
  202. }
  203. UINT glyphs = TestString_Count * iterations;
  204. return(glyphs / seconds / KILO); // Kglyphs/s
  205. }
  206. float Text_Draw_PerGlyph_30pt_Antialiased_LinearGradient(Graphics *g, HDC hdc)
  207. {
  208. UINT iterations;
  209. float seconds;
  210. if (!g) return(0); // No GDI equivalent
  211. g->SetTextRenderingHint(TextRenderingHintAntiAlias);
  212. FontFamily fontFamily(L"Arial");
  213. Font font(&fontFamily, 30);
  214. StringFormat stringFormat(0);
  215. LinearGradientBrush brush(Point(0, 0), Point(512, 512), Color::Red, Color::Blue);
  216. PointF origin(0, 0);
  217. // Don't count font realization towards per-glyph time:
  218. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  219. StartTimer();
  220. do {
  221. PointF origin(64, 64);
  222. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  223. } while (!EndTimer());
  224. g->Flush(FlushIntentionSync);
  225. GetTimer(&seconds, &iterations);
  226. UINT glyphs = TestString_Count * iterations;
  227. return(glyphs / seconds / KILO); // Kglyphs/s
  228. }
  229. float Text_Draw_PerCall_30pt_Antialiased_LinearGradient(Graphics *g, HDC hdc)
  230. {
  231. UINT iterations;
  232. float seconds;
  233. if (!g) return(0); // No GDI equivalent
  234. g->SetTextRenderingHint(TextRenderingHintAntiAlias);
  235. FontFamily fontFamily(L"Arial");
  236. Font font(&fontFamily, 30);
  237. StringFormat stringFormat(0);
  238. LinearGradientBrush brush(Point(0, 0), Point(512, 512), Color::Red, Color::Blue);
  239. PointF origin(0, 0);
  240. StartTimer();
  241. do {
  242. PointF origin(64, 64);
  243. g->DrawString(L"A", 1, &font, origin, &stringFormat, &brush);
  244. } while (!EndTimer());
  245. g->Flush(FlushIntentionSync);
  246. GetTimer(&seconds, &iterations);
  247. UINT glyphs = TestString_Count * iterations;
  248. return(glyphs / seconds / KILO); // Kglyphs/s
  249. }
  250. float Text_Draw_PerCall_30pt_Cleartype(Graphics *g, HDC hdc)
  251. {
  252. UINT iterations;
  253. float seconds;
  254. if (!g) return(0); // No accessible GDI equivalent
  255. g->SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
  256. FontFamily fontFamily(L"Arial");
  257. Font font(&fontFamily, 30);
  258. StringFormat stringFormat(0);
  259. SolidBrush brush(Color::Red);
  260. PointF origin(0, 0);
  261. StartTimer();
  262. do {
  263. PointF origin(64, 64);
  264. g->DrawString(L"A", 1, &font, origin, &stringFormat, &brush);
  265. } while (!EndTimer());
  266. g->Flush(FlushIntentionSync);
  267. GetTimer(&seconds, &iterations);
  268. return(iterations / seconds / KILO); // Calls per second
  269. }
  270. float Text_Draw_PerGlyph_30pt_Cleartype(Graphics *g, HDC hdc)
  271. {
  272. UINT iterations;
  273. float seconds;
  274. if (!g) return(0); // No accessible GDI equivalent
  275. g->SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
  276. FontFamily fontFamily(L"Arial");
  277. Font font(&fontFamily, 30);
  278. StringFormat stringFormat(0);
  279. SolidBrush brush(Color::Red);
  280. PointF origin(0, 0);
  281. // Don't count font realization towards per-glyph time:
  282. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  283. StartTimer();
  284. do {
  285. PointF origin(64, 64);
  286. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  287. } while (!EndTimer());
  288. g->Flush(FlushIntentionSync);
  289. GetTimer(&seconds, &iterations);
  290. UINT glyphs = TestString_Count * iterations;
  291. return(glyphs / seconds / KILO); // Kglyphs/s
  292. }
  293. float Text_Draw_PerGlyph_30pt_Cleartype_LinearGradient(Graphics *g, HDC hdc)
  294. {
  295. UINT iterations;
  296. float seconds;
  297. if (!g) return(0); // No GDI equivalent
  298. g->SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
  299. FontFamily fontFamily(L"Arial");
  300. Font font(&fontFamily, 30);
  301. StringFormat stringFormat(0);
  302. LinearGradientBrush brush(Point(0, 0), Point(512, 512), Color::Red, Color::Blue);
  303. PointF origin(0, 0);
  304. // Don't count font realization towards per-glyph time:
  305. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  306. StartTimer();
  307. do {
  308. PointF origin(64, 64);
  309. g->DrawString(TestStringW, TestString_Count, &font, origin, &stringFormat, &brush);
  310. } while (!EndTimer());
  311. g->Flush(FlushIntentionSync);
  312. GetTimer(&seconds, &iterations);
  313. UINT glyphs = TestString_Count * iterations;
  314. return(glyphs / seconds / KILO); // Kglyphs/s
  315. }
  316. float Text_Draw_PerCall_30pt_Cleartype_LinearGradient(Graphics *g, HDC hdc)
  317. {
  318. UINT iterations;
  319. float seconds;
  320. if (!g) return(0); // No GDI equivalent
  321. g->SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
  322. FontFamily fontFamily(L"Arial");
  323. Font font(&fontFamily, 30);
  324. StringFormat stringFormat(0);
  325. LinearGradientBrush brush(Point(0, 0), Point(512, 512), Color::Red, Color::Blue);
  326. PointF origin(0, 0);
  327. StartTimer();
  328. do {
  329. PointF origin(64, 64);
  330. g->DrawString(L"A", 1, &font, origin, &stringFormat, &brush);
  331. } while (!EndTimer());
  332. g->Flush(FlushIntentionSync);
  333. GetTimer(&seconds, &iterations);
  334. UINT glyphs = TestString_Count * iterations;
  335. return(glyphs / seconds / KILO); // Kglyphs/s
  336. }
  337. ////////////////////////////////////////////////////////////////////////////////
  338. // Add tests for this file here. Always use the 'T' macro for adding entries.
  339. // The parameter meanings are as follows:
  340. //
  341. // Parameter
  342. // ---------
  343. // 1 UniqueIdentifier - Must be a unique number assigned to no other test
  344. // 2 Priority - On a scale of 1 to 5, how important is the test?
  345. // 3 Function - Function name
  346. // 4 Comment - Anything to describe the test
  347. Test TextTests[] =
  348. {
  349. T(4000, 1, Text_Draw_PerCall_30pt_Aliased, "Kcalls/s"),
  350. T(4001, 1, Text_Draw_PerGlyph_30pt_Aliased, "Kglyphs/s"),
  351. T(4002, 1, Text_Draw_PerCall_30pt_LinearGradient, "Kcalls/s"),
  352. T(4003, 1, Text_Draw_PerGlyph_30pt_LinearGradient, "Kglyphs/s"),
  353. T(4004, 1, Text_Draw_PerCall_30pt_Antialiased, "Kcalls/s"),
  354. T(4005, 1, Text_Draw_PerGlyph_30pt_Antialiased, "Kglyphs/s"),
  355. T(4006, 1, Text_Draw_PerCall_30pt_Antialiased_LinearGradient, "Kcalls/s"),
  356. T(4007, 1, Text_Draw_PerGlyph_30pt_Antialiased_LinearGradient, "Kglyphs/s"),
  357. T(4008, 1, Text_Draw_PerCall_30pt_Cleartype, "Kcalls/s"),
  358. T(4009, 1, Text_Draw_PerGlyph_30pt_Cleartype, "Kglyphs/s"),
  359. T(4010, 1, Text_Draw_PerCall_30pt_Cleartype_LinearGradient, "Kcalls/s"),
  360. T(4011, 1, Text_Draw_PerGlyph_30pt_Cleartype_LinearGradient, "Kglyphs/s"),
  361. };
  362. INT TextTests_Count = sizeof(TextTests) / sizeof(TextTests[0]);