headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / servers / app / benchmark / VerticalLineTest.cpp
blobe9390bb4bd928e1f49d05dbe80a9209bcc1b51d0
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 "VerticalLineTest.h"
8 #include <stdio.h>
10 #include <View.h>
12 #include "TestSupport.h"
15 VerticalLineTest::VerticalLineTest()
16 : Test(),
17 fTestDuration(0),
18 fTestStart(-1),
20 fLinesRendered(0),
22 fIterations(0),
23 fMaxIterations(1500),
25 fViewBounds(0, 0, -1, -1)
30 VerticalLineTest::~VerticalLineTest()
35 void
36 VerticalLineTest::Prepare(BView* view)
38 fViewBounds = view->Bounds();
40 fTestDuration = 0;
41 fLinesRendered = 0;
42 fIterations = 0;
43 fTestStart = system_time();
46 bool
47 VerticalLineTest::RunIteration(BView* view)
49 float x = 1;
51 bigtime_t now = system_time();
53 while (true) {
54 view->StrokeLine(BPoint(x, fViewBounds.top + 1),
55 BPoint(x, fViewBounds.bottom - 1));
57 fLinesRendered++;
59 // offset text location
60 x += 2;
61 if (x > fViewBounds.right)
62 break;
65 view->Sync();
67 fTestDuration += system_time() - now;
68 fIterations++;
70 return fIterations < fMaxIterations;
74 void
75 VerticalLineTest::PrintResults(BView* view)
77 if (fTestDuration == 0) {
78 printf("Test was not run.\n");
79 return;
81 bigtime_t timeLeak = system_time() - fTestStart - fTestDuration;
83 Test::PrintResults(view);
85 printf("Line height: %ld\n", fViewBounds.IntegerHeight() + 1 - 2);
86 printf("Lines per iteration: %ld\n", fViewBounds.IntegerWidth() / 2);
87 printf("Total lines rendered: %llu\n", fLinesRendered);
88 printf("Lines per second: %.3f\n",
89 fLinesRendered * 1000000.0 / fTestDuration);
90 printf("Average time between iterations: %.4f seconds.\n",
91 (float)timeLeak / fIterations / 1000000);
95 Test*
96 VerticalLineTest::CreateTest()
98 return new VerticalLineTest();