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 "RandomLineTest.h"
12 #include "TestSupport.h"
15 RandomLineTest::RandomLineTest()
21 fLinesPerIteration(100),
26 fViewBounds(0, 0, -1, -1)
31 RandomLineTest::~RandomLineTest()
37 RandomLineTest::Prepare(BView
* view
)
39 fViewBounds
= view
->Bounds();
44 fTestStart
= system_time();
48 RandomLineTest::RunIteration(BView
* view
)
50 bigtime_t now
= system_time();
52 float vMiddle
= (fViewBounds
.top
+ fViewBounds
.bottom
) / 2;
54 for (uint32 i
= 0; i
< fLinesPerIteration
; i
++) {
55 view
->SetHighColor(rand() % 255, rand() % 255, rand() % 255);
58 a
.x
= random_number_between(fViewBounds
.left
, fViewBounds
.right
);
59 a
.y
= random_number_between(fViewBounds
.top
, vMiddle
);
61 b
.x
= random_number_between(fViewBounds
.left
, fViewBounds
.right
);
62 b
.y
= random_number_between(vMiddle
, fViewBounds
.bottom
);
64 view
->StrokeLine(a
, b
);
71 fTestDuration
+= system_time() - now
;
74 return fIterations
< fMaxIterations
;
79 RandomLineTest::PrintResults(BView
* view
)
81 if (fTestDuration
== 0) {
82 printf("Test was not run.\n");
85 bigtime_t timeLeak
= system_time() - fTestStart
- fTestDuration
;
87 Test::PrintResults(view
);
89 printf("Lines per iteration: %lu\n", fLinesPerIteration
);
90 printf("Total lines rendered: %llu\n", fLinesRendered
);
91 printf("Lines per second: %.3f\n",
92 fLinesRendered
* 1000000.0 / fTestDuration
);
93 printf("Average time between iterations: %.4f seconds.\n",
94 (float)timeLeak
/ fIterations
/ 1000000);
99 RandomLineTest::CreateTest()
101 return new RandomLineTest();