Profiling

From OTBWiki
Revision as of 16:13, 26 May 2015 by Luc.hermitte (Talk | contribs) (A few more tips from my analyses)

Jump to: navigation, search

This page compiles some profiling conclusions and tips:

Method GetSize()

  • Avoid:

for (int i=0;i<v.GetSize();++i) {}

  • Prefer:

const unsigned int size = v.GetSize(); for (unsigned int i=0;i<size;++i) {}

Defensive Programming

  • Avoid defensive programming in function called many times. i.e. avoid testing for programming errors. In particular never use std::vector<>::at()
  • Prefer narrow contracts, and test for possible runtime errors before calling functions that have contracts. For more information, see these posts (in French).

Pixel values

Pixel values from otb::VectorImage are actually dynamic vectors. As such avoid to create, copy et destroy pixel values. Instead prefer to minimize the number of pixel objects created (e.g. try to stick to only one instance declared outside a loop), and then assign them new values.

This is also true for generic algorithms that may work on scalar as well as vector pixels.

Calling static_cast<> on pixels is not recommended either as this may induce a converting-construction. Prefer the new itk::CastInto<> or it::MoveInto<> functions which will be proposed as a patch.