diff --git a/src/tests/servers/app/benchmark/Benchmark.cpp b/src/tests/servers/app/benchmark/Benchmark.cpp index ed68f49e34..0727fbeafb 100644 --- a/src/tests/servers/app/benchmark/Benchmark.cpp +++ b/src/tests/servers/app/benchmark/Benchmark.cpp @@ -11,13 +11,21 @@ #include "TestWindow.h" // tests +#include "ClippedLineTest.h" +#include "HorizontalLineTest.h" +#include "RandomLineTest.h" #include "StringTest.h" +#include "VerticalLineTest.h" class Benchmark : public BApplication { public: Benchmark() : BApplication("application/x-vnd.haiku-benchmark"), - fTest(new StringTest), + fTest(new ClippedLineTest), +// fTest(new HorizontalLineTest), +// fTest(new RandomLineTest), +// fTest(new StringTest), +// fTest(new VerticalLineTest), fTestWindow(NULL) { } diff --git a/src/tests/servers/app/benchmark/ClippedLineTest.cpp b/src/tests/servers/app/benchmark/ClippedLineTest.cpp new file mode 100644 index 0000000000..d651e96c6c --- /dev/null +++ b/src/tests/servers/app/benchmark/ClippedLineTest.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2008 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "ClippedLineTest.h" + +#include + +#include +#include + +#include "TestSupport.h" + + +ClippedLineTest::ClippedLineTest() + : Test(), + fTestDuration(0), + fTestStart(-1), + + fLinesRendered(0), + fLinesPerIteration(20), + + fIterations(0), + fMaxIterations(100), + + 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 fIterations < fMaxIterations; +} + + +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("Lines per second: %.3f\n", + fLinesRendered * 1000000.0 / fTestDuration); + printf("Average time between iterations: %.4f seconds.\n", + (float)timeLeak / fIterations / 1000000); +} + diff --git a/src/tests/servers/app/benchmark/ClippedLineTest.h b/src/tests/servers/app/benchmark/ClippedLineTest.h new file mode 100644 index 0000000000..27a960aeef --- /dev/null +++ b/src/tests/servers/app/benchmark/ClippedLineTest.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2008 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef CLIPPED_LINE_TEST_H +#define CLIPPED_LINE_TEST_H + +#include + +#include "Test.h" + +class ClippedLineTest : public Test { +public: + ClippedLineTest(); + virtual ~ClippedLineTest(); + + virtual void Prepare(BView* view); + virtual bool RunIteration(BView* view); + virtual void PrintResults(); + +private: + bigtime_t fTestDuration; + bigtime_t fTestStart; + uint64 fLinesRendered; + uint32 fLinesPerIteration; + + uint32 fIterations; + uint32 fMaxIterations; + + BRect fViewBounds; +}; + +#endif // CLIPPED_LINE_TEST_H diff --git a/src/tests/servers/app/benchmark/HorizontalLineTest.cpp b/src/tests/servers/app/benchmark/HorizontalLineTest.cpp new file mode 100644 index 0000000000..24c8d45243 --- /dev/null +++ b/src/tests/servers/app/benchmark/HorizontalLineTest.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2008 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "HorizontalLineTest.h" + +#include + +#include + +#include "TestSupport.h" + + +HorizontalLineTest::HorizontalLineTest() + : Test(), + fTestDuration(0), + fTestStart(-1), + + fLinesRendered(0), + + fIterations(0), + fMaxIterations(1500), + + fViewBounds(0, 0, -1, -1) +{ +} + + +HorizontalLineTest::~HorizontalLineTest() +{ +} + + +void +HorizontalLineTest::Prepare(BView* view) +{ + fViewBounds = view->Bounds(); + + fTestDuration = 0; + fLinesRendered = 0; + fIterations = 0; + fTestStart = system_time(); +} + +bool +HorizontalLineTest::RunIteration(BView* view) +{ + float y = 1; + + bigtime_t now = system_time(); + + while (true) { + view->StrokeLine(BPoint(fViewBounds.left + 1, y), + BPoint(fViewBounds.right - 1, y)); + + fLinesRendered++; + + // offset text location + y += 2; + if (y > fViewBounds.bottom) + break; + } + + view->Sync(); + + fTestDuration += system_time() - now; + fIterations++; + + return fIterations < fMaxIterations; +} + + +void +HorizontalLineTest::PrintResults() +{ + if (fTestDuration == 0) { + printf("Test was not run.\n"); + return; + } + bigtime_t timeLeak = system_time() - fTestStart - fTestDuration; + printf("Line width: %ld\n", fViewBounds.IntegerWidth() + 1 - 2); + printf("Lines per iteration: %ld\n", fViewBounds.IntegerHeight() / 2); + printf("Lines per second: %.3f\n", + fLinesRendered * 1000000.0 / fTestDuration); + printf("Average time between iterations: %.4f seconds.\n", + (float)timeLeak / fIterations / 1000000); +} + diff --git a/src/tests/servers/app/benchmark/HorizontalLineTest.h b/src/tests/servers/app/benchmark/HorizontalLineTest.h new file mode 100644 index 0000000000..04c600d5ff --- /dev/null +++ b/src/tests/servers/app/benchmark/HorizontalLineTest.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2008 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef HORIZONTAL_LINE_TEST_H +#define HORIZONTAL_LINE_TEST_H + +#include + +#include "Test.h" + +class HorizontalLineTest : public Test { +public: + HorizontalLineTest(); + virtual ~HorizontalLineTest(); + + virtual void Prepare(BView* view); + virtual bool RunIteration(BView* view); + virtual void PrintResults(); + +private: + bigtime_t fTestDuration; + bigtime_t fTestStart; + uint64 fLinesRendered; + + uint32 fIterations; + uint32 fMaxIterations; + + BRect fViewBounds; +}; + +#endif // HORIZONTAL_LINE_TEST_H diff --git a/src/tests/servers/app/benchmark/Jamfile b/src/tests/servers/app/benchmark/Jamfile index c612cc5ff5..48c1c7a7fa 100644 --- a/src/tests/servers/app/benchmark/Jamfile +++ b/src/tests/servers/app/benchmark/Jamfile @@ -8,9 +8,13 @@ UseHeaders [ FDirName os interface ] ; Application Benchmark : Benchmark.cpp + ClippedLineTest.cpp + HorizontalLineTest.cpp + RandomLineTest.cpp StringTest.cpp Test.cpp TestWindow.cpp + VerticalLineTest.cpp : be ; diff --git a/src/tests/servers/app/benchmark/RandomLineTest.cpp b/src/tests/servers/app/benchmark/RandomLineTest.cpp new file mode 100644 index 0000000000..b49352b47a --- /dev/null +++ b/src/tests/servers/app/benchmark/RandomLineTest.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2008 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "RandomLineTest.h" + +#include + +#include + +#include "TestSupport.h" + + +RandomLineTest::RandomLineTest() + : Test(), + fTestDuration(0), + fTestStart(-1), + + fLinesRendered(0), + fLinesPerIteration(100), + + fIterations(0), + fMaxIterations(1500), + + fViewBounds(0, 0, -1, -1) +{ +} + + +RandomLineTest::~RandomLineTest() +{ +} + + +void +RandomLineTest::Prepare(BView* view) +{ + fViewBounds = view->Bounds(); + + fTestDuration = 0; + fLinesRendered = 0; + fIterations = 0; + fTestStart = system_time(); +} + +bool +RandomLineTest::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 fIterations < fMaxIterations; +} + + +void +RandomLineTest::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("Lines per second: %.3f\n", + fLinesRendered * 1000000.0 / fTestDuration); + printf("Average time between iterations: %.4f seconds.\n", + (float)timeLeak / fIterations / 1000000); +} + diff --git a/src/tests/servers/app/benchmark/RandomLineTest.h b/src/tests/servers/app/benchmark/RandomLineTest.h new file mode 100644 index 0000000000..74c52d485b --- /dev/null +++ b/src/tests/servers/app/benchmark/RandomLineTest.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2008 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef VERTICAL_LINE_TEST_H +#define VERTICAL_LINE_TEST_H + +#include + +#include "Test.h" + +class RandomLineTest : public Test { +public: + RandomLineTest(); + virtual ~RandomLineTest(); + + virtual void Prepare(BView* view); + virtual bool RunIteration(BView* view); + virtual void PrintResults(); + +private: + bigtime_t fTestDuration; + bigtime_t fTestStart; + uint64 fLinesRendered; + uint32 fLinesPerIteration; + + uint32 fIterations; + uint32 fMaxIterations; + + BRect fViewBounds; +}; + +#endif // VERTICAL_LINE_TEST_H diff --git a/src/tests/servers/app/benchmark/StringTest.cpp b/src/tests/servers/app/benchmark/StringTest.cpp index a5dba46bcf..4896d9fbad 100644 --- a/src/tests/servers/app/benchmark/StringTest.cpp +++ b/src/tests/servers/app/benchmark/StringTest.cpp @@ -36,6 +36,8 @@ StringTest::~StringTest() void StringTest::Prepare(BView* view) { +// SetupClipping(view); + font_height fh; view->GetFontHeight(&fh); fLineHeight = ceilf(fh.ascent) + ceilf(fh.descent) diff --git a/src/tests/servers/app/benchmark/Test.cpp b/src/tests/servers/app/benchmark/Test.cpp index 6e8d8fdd61..3b1474633f 100644 --- a/src/tests/servers/app/benchmark/Test.cpp +++ b/src/tests/servers/app/benchmark/Test.cpp @@ -5,6 +5,9 @@ #include "Test.h" +#include +#include + Test::Test() { @@ -14,3 +17,22 @@ Test::Test() Test::~Test() { } + + +void +Test::SetupClipping(BView* view) +{ + BRect bounds = view->Bounds(); + BRegion clipping(bounds); + BRect grid(bounds.InsetByCopy(10, 10)); + for (float y = grid.top; y < grid.bottom - 5; y += grid.Height() / 20) { + for (float x = grid.left; x < grid.right - 5; + x += grid.Width() / 20) { + BRect r(x, y, x, y); + r.InsetBy(-5, -5); + clipping.Exclude(r); + } + } + + view->ConstrainClippingRegion(&clipping); +} diff --git a/src/tests/servers/app/benchmark/Test.h b/src/tests/servers/app/benchmark/Test.h index 4e127f6e08..faca7b3cc0 100644 --- a/src/tests/servers/app/benchmark/Test.h +++ b/src/tests/servers/app/benchmark/Test.h @@ -15,6 +15,8 @@ public: virtual void Prepare(BView* view) = 0; virtual bool RunIteration(BView* view) = 0; virtual void PrintResults() = 0; + + void SetupClipping(BView* view); }; #endif // TEST_H diff --git a/src/tests/servers/app/benchmark/TestWindow.cpp b/src/tests/servers/app/benchmark/TestWindow.cpp index 9abf13872d..22672172d5 100644 --- a/src/tests/servers/app/benchmark/TestWindow.cpp +++ b/src/tests/servers/app/benchmark/TestWindow.cpp @@ -14,6 +14,12 @@ TestView::TestView(BRect frame, Test* test, drawing_mode mode, fTarget(target) { SetDrawingMode(mode); +} + + +void +TestView::AttachedToWindow() +{ fTest->Prepare(this); } diff --git a/src/tests/servers/app/benchmark/TestWindow.h b/src/tests/servers/app/benchmark/TestWindow.h index c4f76ef86e..4419834224 100644 --- a/src/tests/servers/app/benchmark/TestWindow.h +++ b/src/tests/servers/app/benchmark/TestWindow.h @@ -25,6 +25,7 @@ public: drawing_mode mode, const BMessenger& target); + virtual void AttachedToWindow(); virtual void Draw(BRect updateRect); private: diff --git a/src/tests/servers/app/benchmark/VerticalLineTest.cpp b/src/tests/servers/app/benchmark/VerticalLineTest.cpp new file mode 100644 index 0000000000..90d81a2f7f --- /dev/null +++ b/src/tests/servers/app/benchmark/VerticalLineTest.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2008 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "VerticalLineTest.h" + +#include + +#include + +#include "TestSupport.h" + + +VerticalLineTest::VerticalLineTest() + : Test(), + fTestDuration(0), + fTestStart(-1), + + fLinesRendered(0), + + fIterations(0), + fMaxIterations(1500), + + fViewBounds(0, 0, -1, -1) +{ +} + + +VerticalLineTest::~VerticalLineTest() +{ +} + + +void +VerticalLineTest::Prepare(BView* view) +{ + fViewBounds = view->Bounds(); + + fTestDuration = 0; + fLinesRendered = 0; + fIterations = 0; + fTestStart = system_time(); +} + +bool +VerticalLineTest::RunIteration(BView* view) +{ + float x = 1; + + bigtime_t now = system_time(); + + while (true) { + view->StrokeLine(BPoint(x, fViewBounds.top + 1), + BPoint(x, fViewBounds.bottom - 1)); + + fLinesRendered++; + + // offset text location + x += 2; + if (x > fViewBounds.right) + break; + } + + view->Sync(); + + fTestDuration += system_time() - now; + fIterations++; + + return fIterations < fMaxIterations; +} + + +void +VerticalLineTest::PrintResults() +{ + if (fTestDuration == 0) { + printf("Test was not run.\n"); + return; + } + bigtime_t timeLeak = system_time() - fTestStart - fTestDuration; + printf("Line height: %ld\n", fViewBounds.IntegerHeight() + 1 - 2); + printf("Lines per iteration: %ld\n", fViewBounds.IntegerWidth() / 2); + printf("Lines per second: %.3f\n", + fLinesRendered * 1000000.0 / fTestDuration); + printf("Average time between iterations: %.4f seconds.\n", + (float)timeLeak / fIterations / 1000000); +} + diff --git a/src/tests/servers/app/benchmark/VerticalLineTest.h b/src/tests/servers/app/benchmark/VerticalLineTest.h new file mode 100644 index 0000000000..d2a936d22a --- /dev/null +++ b/src/tests/servers/app/benchmark/VerticalLineTest.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2008 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef VERTICAL_LINE_TEST_H +#define VERTICAL_LINE_TEST_H + +#include + +#include "Test.h" + +class VerticalLineTest : public Test { +public: + VerticalLineTest(); + virtual ~VerticalLineTest(); + + virtual void Prepare(BView* view); + virtual bool RunIteration(BView* view); + virtual void PrintResults(); + +private: + bigtime_t fTestDuration; + bigtime_t fTestStart; + uint64 fLinesRendered; + + uint32 fIterations; + uint32 fMaxIterations; + + BRect fViewBounds; +}; + +#endif // VERTICAL_LINE_TEST_H