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 "HorizontalLineTest.h" 7 8 #include <stdio.h> 9 10 #include <View.h> 11 12 #include "TestSupport.h" 13 14 15 HorizontalLineTest::HorizontalLineTest() 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 30 HorizontalLineTest::~HorizontalLineTest() 31 { 32 } 33 34 35 void 36 HorizontalLineTest::Prepare(BView* view) 37 { 38 fViewBounds = view->Bounds(); 39 40 fTestDuration = 0; 41 fLinesRendered = 0; 42 fIterations = 0; 43 fTestStart = system_time(); 44 } 45 46 bool 47 HorizontalLineTest::RunIteration(BView* view) 48 { 49 float y = 1; 50 51 bigtime_t now = system_time(); 52 53 while (true) { 54 view->StrokeLine(BPoint(fViewBounds.left + 1, y), 55 BPoint(fViewBounds.right - 1, y)); 56 57 fLinesRendered++; 58 59 // offset text location 60 y += 2; 61 if (y > fViewBounds.bottom) 62 break; 63 } 64 65 view->Sync(); 66 67 fTestDuration += system_time() - now; 68 fIterations++; 69 70 return fIterations < fMaxIterations; 71 } 72 73 74 void 75 HorizontalLineTest::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 width: %ld\n", fViewBounds.IntegerWidth() + 1 - 2); 86 printf("Lines per iteration: %ld\n", fViewBounds.IntegerHeight() / 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 95 Test* 96 HorizontalLineTest::CreateTest() 97 { 98 return new HorizontalLineTest(); 99 } 100 101