headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / servers / app / benchmark / RandomLineTest.cpp
bloba457810c7a1fe11a63fab406b08feec336d156c9
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 */
6 #include "RandomLineTest.h"
8 #include <stdio.h>
10 #include <View.h>
12 #include "TestSupport.h"
15 RandomLineTest::RandomLineTest()
16 : Test(),
17 fTestDuration(0),
18 fTestStart(-1),
20 fLinesRendered(0),
21 fLinesPerIteration(100),
23 fIterations(0),
24 fMaxIterations(1500),
26 fViewBounds(0, 0, -1, -1)
31 RandomLineTest::~RandomLineTest()
36 void
37 RandomLineTest::Prepare(BView* view)
39 fViewBounds = view->Bounds();
41 fTestDuration = 0;
42 fLinesRendered = 0;
43 fIterations = 0;
44 fTestStart = system_time();
47 bool
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);
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);
64 view->StrokeLine(a, b);
66 fLinesRendered++;
69 view->Sync();
71 fTestDuration += system_time() - now;
72 fIterations++;
74 return fIterations < fMaxIterations;
78 void
79 RandomLineTest::PrintResults(BView* view)
81 if (fTestDuration == 0) {
82 printf("Test was not run.\n");
83 return;
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);
98 Test*
99 RandomLineTest::CreateTest()
101 return new RandomLineTest();