1 /*
2 * Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
4 */
5
6 #include "RandomLineTest.h"
7
8 #include <stdio.h>
9
10 #include <View.h>
11
12 #include "TestSupport.h"
13
14
RandomLineTest()15 RandomLineTest::RandomLineTest()
16 : Test(),
17 fTestDuration(0),
18 fTestStart(-1),
19
20 fLinesRendered(0),
21 fLinesPerIteration(100),
22
23 fIterations(0),
24 fMaxIterations(1500),
25
26 fViewBounds(0, 0, -1, -1)
27 {
28 }
29
30
~RandomLineTest()31 RandomLineTest::~RandomLineTest()
32 {
33 }
34
35
36 void
Prepare(BView * view)37 RandomLineTest::Prepare(BView* view)
38 {
39 fViewBounds = view->Bounds();
40
41 fTestDuration = 0;
42 fLinesRendered = 0;
43 fIterations = 0;
44 fTestStart = system_time();
45 }
46
47 bool
RunIteration(BView * view)48 RandomLineTest::RunIteration(BView* view)
49 {
50 bigtime_t now = system_time();
51
52 float vMiddle = (fViewBounds.top + fViewBounds.bottom) / 2;
53
54 for (uint32 i = 0; i < fLinesPerIteration; i++) {
55 view->SetHighColor(rand() % 255, rand() % 255, rand() % 255);
56
57 BPoint a;
58 a.x = random_number_between(fViewBounds.left, fViewBounds.right);
59 a.y = random_number_between(fViewBounds.top, vMiddle);
60 BPoint b;
61 b.x = random_number_between(fViewBounds.left, fViewBounds.right);
62 b.y = random_number_between(vMiddle, fViewBounds.bottom);
63
64 view->StrokeLine(a, b);
65
66 fLinesRendered++;
67 }
68
69 view->Sync();
70
71 fTestDuration += system_time() - now;
72 fIterations++;
73
74 return fIterations < fMaxIterations;
75 }
76
77
78 void
PrintResults(BView * view)79 RandomLineTest::PrintResults(BView* view)
80 {
81 if (fTestDuration == 0) {
82 printf("Test was not run.\n");
83 return;
84 }
85 bigtime_t timeLeak = system_time() - fTestStart - fTestDuration;
86
87 Test::PrintResults(view);
88
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);
95 }
96
97
98 Test*
CreateTest()99 RandomLineTest::CreateTest()
100 {
101 return new RandomLineTest();
102 }
103
104
105