1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*=========================================================================
Program: Visualization Toolkit
Module: BenchmarkFreeTypeRendering.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkFreeTypeTools.h"
#include "vtkFreeTypeUtilities.h"
#include "vtkTextRenderer.h"
#include "vtkImageData.h"
#include "vtkNew.h"
#include "vtkStdString.h"
#include "vtkTextProperty.h"
#include <ctime>
#include <cstdio>
#include <algorithm>
//----------------------------------------------------------------------------
int BenchmarkFreeTypeRendering(int , char *[])
{
clock_t startT;
clock_t endT;
double elapsedSecs;
double minSecs;
double maxSecs;
double aveSecs;
vtkFreeTypeTools *ftTools = vtkFreeTypeTools::GetInstance();
vtkFreeTypeUtilities *ftUtils = vtkFreeTypeUtilities::GetInstance();
vtkNew<vtkTextProperty> tprop;
vtkNew<vtkTextRenderer> textRenderer;
vtkStdString str;
for (int i = 0; i < 500; ++i)
{
str += "I'm a test string!\n";
}
elapsedSecs = 0;
minSecs = VTK_DOUBLE_MAX;
maxSecs = 0;
aveSecs = 0;
for (int i = 0; i < 100; ++i)
{
// Set the font to something different to throw off the FT caches.
tprop->SetFontFamily(i % VTK_UNKNOWN_FONT);
tprop->SetFontSize(i % 50 + 10);
tprop->SetBold(i % 2);
tprop->SetItalic((i % 51) % 2);
tprop->SetOrientation(static_cast<double>(i) * (360.0 / 100.0));
// Reset the image data
vtkNew<vtkImageData> image;
// Clock the time needed to render the string.
startT = clock();
ftTools->RenderString(tprop.GetPointer(), str, image.GetPointer());
endT = clock();
double iterSecs = static_cast<double>(endT - startT) /
static_cast<double>(CLOCKS_PER_SEC);
elapsedSecs += iterSecs;
minSecs = std::min(minSecs, iterSecs);
maxSecs = std::max(maxSecs, iterSecs);
}
aveSecs = elapsedSecs / 100.0;
printf("FTTools Total: %9.5f Min: %9.5f Max: %9.5f Ave: %9.5f\n",
elapsedSecs, minSecs, maxSecs, aveSecs);
elapsedSecs = 0;
minSecs = VTK_DOUBLE_MAX;
maxSecs = 0;
aveSecs = 0;
for (int i = 0; i < 100; ++i)
{
// Set the font to something different to throw off the FT face cache.
tprop->SetFontFamily(i % VTK_UNKNOWN_FONT);
tprop->SetFontSize(i % 50 + 10);
tprop->SetBold(i % 2);
tprop->SetItalic((i % 51) % 2);
tprop->SetOrientation(static_cast<double>(i) * (360.0 / 100.0));
// Reset the image data
vtkNew<vtkImageData> image;
// Clock the time needed to render the string.
startT = clock();
textRenderer->RenderString(tprop.GetPointer(), str, image.GetPointer());
endT = clock();
double iterSecs = static_cast<double>(endT - startT) /
static_cast<double>(CLOCKS_PER_SEC);
elapsedSecs += iterSecs;
minSecs = std::min(minSecs, iterSecs);
maxSecs = std::max(maxSecs, iterSecs);
}
aveSecs = elapsedSecs / 100.0;
printf("TextRen Total: %9.5f Min: %9.5f Max: %9.5f Ave: %9.5f\n",
elapsedSecs, minSecs, maxSecs, aveSecs);
elapsedSecs = 0;
minSecs = VTK_DOUBLE_MAX;
maxSecs = 0;
aveSecs = 0;
for (int i = 0; i < 100; ++i)
{
// Set the font to something different to throw off the FT face cache.
tprop->SetFontFamily(i % VTK_UNKNOWN_FONT);
tprop->SetFontSize(i % 50 + 10);
tprop->SetBold(i % 2);
tprop->SetItalic((i % 51) % 2);
tprop->SetOrientation(static_cast<double>(i) * (360.0 / 100.0));
// Reset the image data
vtkNew<vtkImageData> image;
// Clock the time needed to render the string.
startT = clock();
ftUtils->RenderString(tprop.GetPointer(), str, image.GetPointer());
endT = clock();
double iterSecs = static_cast<double>(endT - startT) /
static_cast<double>(CLOCKS_PER_SEC);
elapsedSecs += iterSecs;
minSecs = std::min(minSecs, iterSecs);
maxSecs = std::max(maxSecs, iterSecs);
}
aveSecs = elapsedSecs / 100.0;
printf("FTUtils Total: %9.5f Min: %9.5f Max: %9.5f Ave: %9.5f\n",
elapsedSecs, minSecs, maxSecs, aveSecs);
return EXIT_SUCCESS;
}
|