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 "VerticalLineTest.h"
7
8#include <stdio.h>
9
10#include <View.h>
11
12#include "TestSupport.h"
13
14
15VerticalLineTest::VerticalLineTest()
16	: Test(),
17	  fTestDuration(0),
18	  fTestStart(-1),
19
20	  fLinesRendered(0),
21
22	  fIterations(0),
23	  fMaxIterations(1500),
24
25	  fViewBounds(0, 0, -1, -1)
26{
27}
28
29
30VerticalLineTest::~VerticalLineTest()
31{
32}
33
34
35void
36VerticalLineTest::Prepare(BView* view)
37{
38	fViewBounds = view->Bounds();
39
40	fTestDuration = 0;
41	fLinesRendered = 0;
42	fIterations = 0;
43	fTestStart = system_time();
44}
45
46bool
47VerticalLineTest::RunIteration(BView* view)
48{
49	float x = 1;
50
51	bigtime_t now = system_time();
52
53	while (true) {
54		view->StrokeLine(BPoint(x, fViewBounds.top + 1),
55			BPoint(x, fViewBounds.bottom - 1));
56
57		fLinesRendered++;
58
59		// offset text location
60		x += 2;
61		if (x > fViewBounds.right)
62			break;
63	}
64
65	view->Sync();
66
67	fTestDuration += system_time() - now;
68	fIterations++;
69
70	return fIterations < fMaxIterations;
71}
72
73
74void
75VerticalLineTest::PrintResults(BView* view)
76{
77	if (fTestDuration == 0) {
78		printf("Test was not run.\n");
79		return;
80	}
81	bigtime_t timeLeak = system_time() - fTestStart - fTestDuration;
82
83	Test::PrintResults(view);
84
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);
92}
93
94
95Test*
96VerticalLineTest::CreateTest()
97{
98	return new VerticalLineTest();
99}
100
101