wpfperformancedrawingbrush

DrawingBrush Performance


Are there any differences when it comes to performance between the following three border objects?

<Border Grid.Column="0" Grid.ColumnSpan="2" Opacity="1">
  <Border.Background>
    <DrawingBrush>
      <DrawingBrush.Drawing>
        <DrawingGroup>
          <GeometryDrawing Brush="Red">
            <GeometryDrawing.Geometry>
              <GeometryGroup>
                <RectangleGeometry Rect="0,0 100,1000" />
                <LineGeometry StartPoint="0,0" EndPoint="100,1000"/>
                <LineGeometry StartPoint="100,0" EndPoint="0,1000"/>
              </GeometryGroup>
            </GeometryDrawing.Geometry>
            <GeometryDrawing.Pen>
              <Pen Thickness="20" Brush="Black"/>
            </GeometryDrawing.Pen>
          </GeometryDrawing>
        </DrawingGroup>
      </DrawingBrush.Drawing>
    </DrawingBrush>
  </Border.Background>
</Border>

<Border Grid.Column="0" Grid.ColumnSpan="2" Opacity="1">
  <Border.Background>
    <DrawingBrush>
      <DrawingBrush.Drawing>
        <DrawingGroup>
          <GeometryDrawing Brush="Red">
            <GeometryDrawing.Geometry>
              <RectangleGeometry Rect="0,0 100,1000" />
            </GeometryDrawing.Geometry>
            <GeometryDrawing.Pen>
              <Pen Thickness="20" Brush="Black"/>
            </GeometryDrawing.Pen>
          </GeometryDrawing>
          <GeometryDrawing>
            <GeometryDrawing.Geometry>
              <LineGeometry StartPoint="0,0" EndPoint="100,1000"/>
            </GeometryDrawing.Geometry>
            <GeometryDrawing.Pen>
              <Pen Thickness="20" Brush="Black"/>
            </GeometryDrawing.Pen>
          </GeometryDrawing>
          <GeometryDrawing>
            <GeometryDrawing.Geometry>
              <LineGeometry StartPoint="100,0" EndPoint="0,1000"/>
            </GeometryDrawing.Geometry>
            <GeometryDrawing.Pen>
              <Pen Thickness="20" Brush="Black"/>
            </GeometryDrawing.Pen>
          </GeometryDrawing>
        </DrawingGroup>
      </DrawingBrush.Drawing>
    </DrawingBrush>
  </Border.Background>
</Border>

<Border Grid.Column="3" Grid.ColumnSpan="2" Opacity="1">
  <Image Stretch="Uniform">
    <Image.Source>
      <DrawingImage>
        <DrawingImage.Drawing>
          <DrawingGroup>
            <GeometryDrawing Brush="Red">
              <GeometryDrawing.Geometry>
                <GeometryGroup>
                  <RectangleGeometry Rect="0,0 100,1000" />
                  <LineGeometry StartPoint="0,0" EndPoint="100,1000"/>
                  <LineGeometry StartPoint="100,0" EndPoint="0,1000"/>
                </GeometryGroup>
              </GeometryDrawing.Geometry>
              <GeometryDrawing.Pen>
                <Pen Thickness="20" Brush="Black"/>
              </GeometryDrawing.Pen>
            </GeometryDrawing>
          </DrawingGroup>
        </DrawingImage.Drawing>
      </DrawingImage>
    </Image.Source>
  </Image>
</Border>

Solution

  • Here's the standard answer for questions such as yours which boil down to 'Is A faster than B?' ...

    Try both (or all three or however many) and measure the execution times. Arguments from first principles won't answer the question, though they may generate a lot of hot air.

    Please don't think I'm brushing you off with a glib answer, where I work at the moment, parallel computing for geophysics, performance is very very important. Hard won experience tells me that the only way to be certain if A is faster than B is to measure both. And if it's not worth coding both to measure the differences, then the difference isn't important !