diff --git a/src/tests/servers/app/benchmark/Benchmark.cpp b/src/tests/servers/app/benchmark/Benchmark.cpp index d974c506ff..83c78ad5ec 100644 --- a/src/tests/servers/app/benchmark/Benchmark.cpp +++ b/src/tests/servers/app/benchmark/Benchmark.cpp @@ -9,10 +9,10 @@ #include #include +#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; } diff --git a/src/tests/servers/app/benchmark/ClippedLineTest.cpp b/src/tests/servers/app/benchmark/ClippedLineTest.cpp deleted file mode 100644 index 39462679ea..0000000000 --- a/src/tests/servers/app/benchmark/ClippedLineTest.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2008-2009 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), - 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(); -} - diff --git a/src/tests/servers/app/benchmark/ClippedLineTest.h b/src/tests/servers/app/benchmark/ClippedLineTest.h deleted file mode 100644 index dc48fc1609..0000000000 --- a/src/tests/servers/app/benchmark/ClippedLineTest.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2008-2009 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(); - - 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 diff --git a/src/tests/servers/app/benchmark/HorizontalLineTest.cpp b/src/tests/servers/app/benchmark/HorizontalLineTest.cpp index 89f4922429..8620b2617a 100644 --- a/src/tests/servers/app/benchmark/HorizontalLineTest.cpp +++ b/src/tests/servers/app/benchmark/HorizontalLineTest.cpp @@ -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", diff --git a/src/tests/servers/app/benchmark/HorizontalLineTest.h b/src/tests/servers/app/benchmark/HorizontalLineTest.h index 99c1d56d30..b930e9fa63 100644 --- a/src/tests/servers/app/benchmark/HorizontalLineTest.h +++ b/src/tests/servers/app/benchmark/HorizontalLineTest.h @@ -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(); diff --git a/src/tests/servers/app/benchmark/Jamfile b/src/tests/servers/app/benchmark/Jamfile index 48c1c7a7fa..2e2dd927a9 100644 --- a/src/tests/servers/app/benchmark/Jamfile +++ b/src/tests/servers/app/benchmark/Jamfile @@ -8,7 +8,7 @@ UseHeaders [ FDirName os interface ] ; Application Benchmark : Benchmark.cpp - ClippedLineTest.cpp + DrawingModeToString.cpp HorizontalLineTest.cpp RandomLineTest.cpp StringTest.cpp diff --git a/src/tests/servers/app/benchmark/RandomLineTest.cpp b/src/tests/servers/app/benchmark/RandomLineTest.cpp index c2844774ee..a457810c7a 100644 --- a/src/tests/servers/app/benchmark/RandomLineTest.cpp +++ b/src/tests/servers/app/benchmark/RandomLineTest.cpp @@ -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", diff --git a/src/tests/servers/app/benchmark/RandomLineTest.h b/src/tests/servers/app/benchmark/RandomLineTest.h index e2a5e67975..d8568e4818 100644 --- a/src/tests/servers/app/benchmark/RandomLineTest.h +++ b/src/tests/servers/app/benchmark/RandomLineTest.h @@ -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(); diff --git a/src/tests/servers/app/benchmark/StringTest.cpp b/src/tests/servers/app/benchmark/StringTest.cpp index 2b09b4419e..64ffc80e21 100644 --- a/src/tests/servers/app/benchmark/StringTest.cpp +++ b/src/tests/servers/app/benchmark/StringTest.cpp @@ -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); diff --git a/src/tests/servers/app/benchmark/StringTest.h b/src/tests/servers/app/benchmark/StringTest.h index dec6bcf708..dd748d2915 100644 --- a/src/tests/servers/app/benchmark/StringTest.h +++ b/src/tests/servers/app/benchmark/StringTest.h @@ -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(); diff --git a/src/tests/servers/app/benchmark/Test.cpp b/src/tests/servers/app/benchmark/Test.cpp index a67dc6e4c7..c090defc99 100644 --- a/src/tests/servers/app/benchmark/Test.cpp +++ b/src/tests/servers/app/benchmark/Test.cpp @@ -5,8 +5,12 @@ #include "Test.h" +#include + #include +#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); +} + + diff --git a/src/tests/servers/app/benchmark/Test.h b/src/tests/servers/app/benchmark/Test.h index 8bb295b49b..ae1cfe7aad 100644 --- a/src/tests/servers/app/benchmark/Test.h +++ b/src/tests/servers/app/benchmark/Test.h @@ -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); diff --git a/src/tests/servers/app/benchmark/TestWindow.cpp b/src/tests/servers/app/benchmark/TestWindow.cpp index 22672172d5..1fec00d5d1 100644 --- a/src/tests/servers/app/benchmark/TestWindow.cpp +++ b/src/tests/servers/app/benchmark/TestWindow.cpp @@ -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(); } diff --git a/src/tests/servers/app/benchmark/TestWindow.h b/src/tests/servers/app/benchmark/TestWindow.h index 4419834224..f6c03581db 100644 --- a/src/tests/servers/app/benchmark/TestWindow.h +++ b/src/tests/servers/app/benchmark/TestWindow.h @@ -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 diff --git a/src/tests/servers/app/benchmark/VerticalLineTest.cpp b/src/tests/servers/app/benchmark/VerticalLineTest.cpp index cdaa1fa9e2..e9390bb4bd 100644 --- a/src/tests/servers/app/benchmark/VerticalLineTest.cpp +++ b/src/tests/servers/app/benchmark/VerticalLineTest.cpp @@ -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", diff --git a/src/tests/servers/app/benchmark/VerticalLineTest.h b/src/tests/servers/app/benchmark/VerticalLineTest.h index 7f5229392c..ef84746011 100644 --- a/src/tests/servers/app/benchmark/VerticalLineTest.h +++ b/src/tests/servers/app/benchmark/VerticalLineTest.h @@ -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();