[gdal-dev] ReadBlock vs. RasterIO performance

Gregory, Matthew matt.gregory at oregonstate.edu
Thu Mar 6 18:25:55 EST 2008


Hi list,

In reading through the previous posts on this topic, I see that
ReadBlock() and RasterIO() should have very similar performance (with
RasterIO() actually doing better when blocks are cached and accessed
multiple times).  But in doing a very simple test (ie. reading a
relatively large single-band GTiff (8000x13000) 200 times), ReadBlock()
seems to be much faster than RasterIO().

ReadBlock() : 21 seconds
RasterIO()  : 87 seconds

Here is the relevant code:

----------

<snipped>
int nXSize, nYSize;
poBand = ds->GetRasterBand(1);

CPLAssert( poBand->GetRasterDataType() == GDT_Byte );
poBand->GetBlockSize( &nXSize, &nYSize );
int nXBlocks = (poBand->GetXSize() + nXSize - 1) / nXSize;
int nYBlocks = (poBand->GetYSize() + nYSize - 1) / nYSize;

GByte* pabyData = (GByte*) new GByte[nXSize * nYSize];

for (int i=0; i<200; i++)
{
  // Using ReadBlock
  if (mode == 1) {
    for( int iYBlock = 0; iYBlock < nYBlocks; iYBlock++ )
      for( int iXBlock = 0; iXBlock < nXBlocks; iXBlock++ )
        poBand->ReadBlock( iXBlock, iYBlock, pabyData );
  } 

  // Using RasterIO
  else {
    for ( int iYBlock = 0; iYBlock < nYBlocks; iYBlock++ )
    {
      for( int iXBlock = 0; iXBlock < nXBlocks; iXBlock++ )
      {
        int nXOff = iXBlock * nXSize;
        int nYOff = iYBlock * nYSize;
        poBand->RasterIO(GF_Read, nXOff, nYOff, nXSize, 
          nYSize, pabyData, nXSize, nYSize, GDT_Byte, 0, 0);
      }
    }
  }
}

----------

1) Am I (likely) doing something incredibly stupid or is this expected?

2) Would you expect differences for different drivers?

I'm on Windows using VC8, quad-core CPU @ 2.66GHz

thanks, matt


More information about the gdal-dev mailing list