One can now chose clipping or no clipping (--clipping or -c) and the drawing

mode. The ClippedLineTest is removed, since that was a dup of RandomLines
anyways.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29953 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2009-04-05 22:10:21 +00:00
parent 224ceba88f
commit 0596ce4f66
16 changed files with 91 additions and 167 deletions

View File

@ -9,10 +9,10 @@
#include <Application.h>
#include <Screen.h>
#include "DrawingModeToString.h"
#include "TestWindow.h"
// tests
#include "ClippedLineTest.h"
#include "HorizontalLineTest.h"
#include "RandomLineTest.h"
#include "StringTest.h"
@ -25,7 +25,6 @@ struct test_info {
};
const test_info kTestInfos[] = {
{ "ClippedLines", ClippedLineTest::CreateTest },
{ "HorizontalLines", HorizontalLineTest::CreateTest },
{ "RandomLines", RandomLineTest::CreateTest },
{ "Strings", StringTest::CreateTest },
@ -36,10 +35,12 @@ const test_info kTestInfos[] = {
class Benchmark : public BApplication {
public:
Benchmark(Test* test)
Benchmark(Test* test, drawing_mode mode, bool clipping)
: BApplication("application/x-vnd.haiku-benchmark"),
fTest(test),
fTestWindow(NULL)
fTestWindow(NULL),
fDrawingMode(mode),
fUseClipping(clipping)
{
}
@ -59,8 +60,8 @@ public:
frame.right = frame.left + width - 1;
frame.bottom = frame.top + height - 1;
fTestWindow = new TestWindow(frame, fTest, B_OP_COPY,
BMessenger(this));
fTestWindow = new TestWindow(frame, fTest, fDrawingMode,
fUseClipping, BMessenger(this));
}
virtual bool QuitRequested()
@ -77,7 +78,9 @@ public:
printf("Test canceled early.\n");
// fall through
case MSG_TEST_FINISHED:
fTest->PrintResults();
fTestWindow->Lock();
fTest->PrintResults(fTestWindow->View());
fTestWindow->Unlock();
PostMessage(B_QUIT_REQUESTED);
break;
default:
@ -89,6 +92,8 @@ public:
private:
Test* fTest;
TestWindow* fTestWindow;
drawing_mode fDrawingMode;
bool fUseClipping;
};
@ -114,7 +119,25 @@ main(int argc, char** argv)
print_test_list(true);
exit(1);
}
testName = argv[1];
// skip program name
argc--;
argv++;
testName = argv[0];
bool clipping = false;
drawing_mode mode = B_OP_COPY;
while (argc > 0) {
drawing_mode possibleMode;
if (strcmp(argv[0], "--clipping") == 0 || strcmp(argv[0], "-c") == 0) {
clipping = true;
} else if (ToDrawingMode(argv[0], possibleMode)) {
mode = possibleMode;
}
argc--;
argv++;
}
// find and create the test
Test* test = NULL;
@ -136,7 +159,7 @@ main(int argc, char** argv)
exit(1);
}
Benchmark app(test);
Benchmark app(test, mode, clipping);
app.Run();
return 0;
}

View File

@ -1,104 +0,0 @@
/*
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "ClippedLineTest.h"
#include <stdio.h>
#include <Region.h>
#include <View.h>
#include "TestSupport.h"
ClippedLineTest::ClippedLineTest()
: Test(),
fTestDuration(0),
fTestStart(-1),
fLinesRendered(0),
fLinesPerIteration(20),
fIterations(0),
fMaxTestDuration(5000000),
fViewBounds(0, 0, -1, -1)
{
}
ClippedLineTest::~ClippedLineTest()
{
}
void
ClippedLineTest::Prepare(BView* view)
{
fViewBounds = view->Bounds();
SetupClipping(view);
fTestDuration = 0;
fLinesRendered = 0;
fIterations = 0;
fTestStart = system_time();
}
bool
ClippedLineTest::RunIteration(BView* view)
{
bigtime_t now = system_time();
float vMiddle = (fViewBounds.top + fViewBounds.bottom) / 2;
for (uint32 i = 0; i < fLinesPerIteration; i++) {
view->SetHighColor(rand() % 255, rand() % 255, rand() % 255);
BPoint a;
a.x = random_number_between(fViewBounds.left, fViewBounds.right);
a.y = random_number_between(fViewBounds.top, vMiddle);
BPoint b;
b.x = random_number_between(fViewBounds.left, fViewBounds.right);
b.y = random_number_between(vMiddle, fViewBounds.bottom);
view->StrokeLine(a, b);
fLinesRendered++;
}
view->Sync();
fTestDuration += system_time() - now;
fIterations++;
return system_time() - fTestStart < fMaxTestDuration;
}
void
ClippedLineTest::PrintResults()
{
if (fTestDuration == 0) {
printf("Test was not run.\n");
return;
}
bigtime_t timeLeak = system_time() - fTestStart - fTestDuration;
printf("Lines per iteration: %lu\n", fLinesPerIteration);
printf("Clipping rects: %ld\n", fClippingRegion.CountRects());
printf("Total lines rendered: %llu\n", fLinesRendered);
printf("Lines per second: %.3f\n",
fLinesRendered * 1000000.0 / fTestDuration);
printf("Average time between iterations: %.4f seconds.\n",
(float)timeLeak / fIterations / 1000000);
}
Test*
ClippedLineTest::CreateTest()
{
return new ClippedLineTest();
}

View File

@ -1,35 +0,0 @@
/*
* Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef CLIPPED_LINE_TEST_H
#define CLIPPED_LINE_TEST_H
#include <Rect.h>
#include "Test.h"
class ClippedLineTest : public Test {
public:
ClippedLineTest();
virtual ~ClippedLineTest();
virtual void Prepare(BView* view);
virtual bool RunIteration(BView* view);
virtual void PrintResults();
static Test* CreateTest();
private:
bigtime_t fTestDuration;
bigtime_t fTestStart;
uint64 fLinesRendered;
uint32 fLinesPerIteration;
uint32 fIterations;
bigtime_t fMaxTestDuration;
BRect fViewBounds;
};
#endif // CLIPPED_LINE_TEST_H

View File

@ -72,15 +72,19 @@ HorizontalLineTest::RunIteration(BView* view)
void
HorizontalLineTest::PrintResults()
HorizontalLineTest::PrintResults(BView* view)
{
if (fTestDuration == 0) {
printf("Test was not run.\n");
return;
}
bigtime_t timeLeak = system_time() - fTestStart - fTestDuration;
Test::PrintResults(view);
printf("Line width: %ld\n", fViewBounds.IntegerWidth() + 1 - 2);
printf("Lines per iteration: %ld\n", fViewBounds.IntegerHeight() / 2);
printf("Total lines rendered: %llu\n", fLinesRendered);
printf("Lines per second: %.3f\n",
fLinesRendered * 1000000.0 / fTestDuration);
printf("Average time between iterations: %.4f seconds.\n",

View File

@ -16,7 +16,7 @@ public:
virtual void Prepare(BView* view);
virtual bool RunIteration(BView* view);
virtual void PrintResults();
virtual void PrintResults(BView* view);
static Test* CreateTest();

View File

@ -8,7 +8,7 @@ UseHeaders [ FDirName os interface ] ;
Application Benchmark :
Benchmark.cpp
ClippedLineTest.cpp
DrawingModeToString.cpp
HorizontalLineTest.cpp
RandomLineTest.cpp
StringTest.cpp

View File

@ -76,14 +76,18 @@ RandomLineTest::RunIteration(BView* view)
void
RandomLineTest::PrintResults()
RandomLineTest::PrintResults(BView* view)
{
if (fTestDuration == 0) {
printf("Test was not run.\n");
return;
}
bigtime_t timeLeak = system_time() - fTestStart - fTestDuration;
Test::PrintResults(view);
printf("Lines per iteration: %lu\n", fLinesPerIteration);
printf("Total lines rendered: %llu\n", fLinesRendered);
printf("Lines per second: %.3f\n",
fLinesRendered * 1000000.0 / fTestDuration);
printf("Average time between iterations: %.4f seconds.\n",

View File

@ -16,7 +16,7 @@ public:
virtual void Prepare(BView* view);
virtual bool RunIteration(BView* view);
virtual void PrintResults();
virtual void PrintResults(BView* view);
static Test* CreateTest();

View File

@ -97,13 +97,16 @@ StringTest::RunIteration(BView* view)
void
StringTest::PrintResults()
StringTest::PrintResults(BView* view)
{
if (fTestDuration == 0) {
printf("Test was not run.\n");
return;
}
bigtime_t timeLeak = system_time() - fTestStart - fTestDuration;
Test::PrintResults(view);
printf("Glyphs per DrawString() call: %ld\n", fGlyphsPerLine);
printf("Glyphs per second: %.3f\n",
fGlyphsRendered * 1000000.0 / fTestDuration);

View File

@ -16,7 +16,7 @@ public:
virtual void Prepare(BView* view);
virtual bool RunIteration(BView* view);
virtual void PrintResults();
virtual void PrintResults(BView* view);
static Test* CreateTest();

View File

@ -5,8 +5,12 @@
#include "Test.h"
#include <stdio.h>
#include <View.h>
#include "DrawingModeToString.h"
Test::Test()
{
@ -35,3 +39,17 @@ Test::SetupClipping(BView* view)
view->ConstrainClippingRegion(&fClippingRegion);
}
void
Test::PrintResults(BView* view)
{
if (fClippingRegion.CountRects() > 0)
printf("Clipping rects: %ld\n", fClippingRegion.CountRects());
const char* string;
if (ToString(view->DrawingMode(), string))
printf("Drawing mode: %s\n", string);
}

View File

@ -16,7 +16,7 @@ public:
virtual void Prepare(BView* view) = 0;
virtual bool RunIteration(BView* view) = 0;
virtual void PrintResults() = 0;
virtual void PrintResults(BView* view);
void SetupClipping(BView* view);

View File

@ -8,10 +8,12 @@
TestView::TestView(BRect frame, Test* test, drawing_mode mode,
const BMessenger& target)
: BView(frame, "test view", B_FOLLOW_ALL, B_WILL_DRAW),
fTest(test),
fTarget(target)
bool useClipping, const BMessenger& target)
:
BView(frame, "test view", B_FOLLOW_ALL, B_WILL_DRAW),
fTest(test),
fTarget(target),
fUseClipping(useClipping)
{
SetDrawingMode(mode);
}
@ -21,6 +23,8 @@ void
TestView::AttachedToWindow()
{
fTest->Prepare(this);
if (fUseClipping)
fTest->SetupClipping(this);
}
@ -37,14 +41,14 @@ TestView::Draw(BRect updateRect)
TestWindow::TestWindow(BRect frame, Test* test, drawing_mode mode,
const BMessenger& target)
bool useClipping, const BMessenger& target)
: BWindow(frame, "Test Window", B_TITLED_WINDOW_LOOK,
B_FLOATING_ALL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
fTarget(target),
fAllowedToQuit(false)
{
TestView* view = new TestView(Bounds(), test, mode, target);
AddChild(view);
fTestView = new TestView(Bounds(), test, mode, useClipping, target);
AddChild(fTestView);
Show();
}

View File

@ -22,7 +22,7 @@ class Test;
class TestView : public BView {
public:
TestView(BRect frame, Test* test,
drawing_mode mode,
drawing_mode mode, bool useClipping,
const BMessenger& target);
virtual void AttachedToWindow();
@ -31,21 +31,24 @@ public:
private:
Test* fTest;
BMessenger fTarget;
bool fUseClipping;
};
// TestWindow
class TestWindow : public BWindow {
public:
TestWindow(BRect fame, Test* test,
drawing_mode mode,
drawing_mode mode, bool useClipping,
const BMessenger& target);
virtual bool QuitRequested();
void SetAllowedToQuit(bool allowed);
BView* View() const { return fTestView; }
private:
BMessenger fTarget;
bool fAllowedToQuit;
TestView* fTestView;
};
#endif // TEST_WINDOW_H

View File

@ -72,15 +72,19 @@ VerticalLineTest::RunIteration(BView* view)
void
VerticalLineTest::PrintResults()
VerticalLineTest::PrintResults(BView* view)
{
if (fTestDuration == 0) {
printf("Test was not run.\n");
return;
}
bigtime_t timeLeak = system_time() - fTestStart - fTestDuration;
Test::PrintResults(view);
printf("Line height: %ld\n", fViewBounds.IntegerHeight() + 1 - 2);
printf("Lines per iteration: %ld\n", fViewBounds.IntegerWidth() / 2);
printf("Total lines rendered: %llu\n", fLinesRendered);
printf("Lines per second: %.3f\n",
fLinesRendered * 1000000.0 / fTestDuration);
printf("Average time between iterations: %.4f seconds.\n",

View File

@ -16,7 +16,7 @@ public:
virtual void Prepare(BView* view);
virtual bool RunIteration(BView* view);
virtual void PrintResults();
virtual void PrintResults(BView* view);
static Test* CreateTest();