2 * Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
6 #include "StringTest.h"
13 #include "TestSupport.h"
16 StringTest::StringTest()
31 StringTest::~StringTest()
37 StringTest::Prepare(BView
* view
)
39 // SetupClipping(view);
42 view
->GetFontHeight(&fh
);
43 fLineHeight
= ceilf(fh
.ascent
) + ceilf(fh
.descent
)
45 fStartHeight
= ceilf(fh
.ascent
) + ceilf(fh
.descent
);
46 fViewBounds
= view
->Bounds();
49 string
.Append('M', fGlyphsPerLine
);
50 while (view
->StringWidth(string
.String()) < fViewBounds
.Width() - 10)
51 string
.Append('M', 1);
52 while (view
->StringWidth(string
.String()) > fViewBounds
.Width() - 10)
53 string
.Remove(string
.Length() - 1, 1);
55 fGlyphsPerLine
= 60; //string.Length();
59 fTestStart
= system_time();
63 StringTest::RunIteration(BView
* view
)
67 textLocation
.y
= random_number_between(fStartHeight
,
68 fStartHeight
+ fLineHeight
/ 2);
70 char buffer
[fGlyphsPerLine
+ 1];
71 buffer
[fGlyphsPerLine
] = 0;
73 bigtime_t now
= system_time();
76 // fill string with random chars
77 for (uint32 j
= 0; j
< fGlyphsPerLine
; j
++)
78 buffer
[j
] = 'A' + rand() % ('z' - 'A');
80 view
->DrawString(buffer
, textLocation
);
82 fGlyphsRendered
+= fGlyphsPerLine
;
84 // offset text location
85 textLocation
.y
+= fLineHeight
;
86 if (textLocation
.y
> fViewBounds
.bottom
)
92 fTestDuration
+= system_time() - now
;
95 return fIterations
< fMaxIterations
;
100 StringTest::PrintResults(BView
* view
)
102 if (fTestDuration
== 0) {
103 printf("Test was not run.\n");
106 bigtime_t timeLeak
= system_time() - fTestStart
- fTestDuration
;
108 Test::PrintResults(view
);
110 printf("Glyphs per DrawString() call: %ld\n", fGlyphsPerLine
);
111 printf("Glyphs per second: %.3f\n",
112 fGlyphsRendered
* 1000000.0 / fTestDuration
);
113 printf("Average time between iterations: %.4f seconds.\n",
114 (float)timeLeak
/ fIterations
/ 1000000);
119 StringTest::CreateTest()
121 return new StringTest();