Accessors are usually called at least once for each element of the accessed collection. Hence, they should be designed carefully in every situation where performance is an issue. For example, one can gain a lot by having the compiler inline accessors. More...
Accessors are usually called at least once for each element of the accessed collection. Hence, they should be designed carefully in every situation where performance is an issue. For example, one can gain a lot by having the compiler inline accessors.
This section describes different types of accessor. In the following, we assume elements to be Particle
s.
functor_weight_accessor
functor_weight_accessor()
An example of functor accessor is trsl::weight_accessor, which always returns 1 — useful if elements have uniform weights.
std::pointer_to_unary_function<const Particle&, double>
std::ptr_fun(function_pointer_weight_accessor)
std::const_mem_fun_ref_t<double, Particle>
std::mem_fun_ref(&Particle::getWeight)
Method pointer is currently the default in trsl::is_picked_systematic (but subject to change, see Discussion). The implementation used in TRSL is not std::const_mem_fun_ref_t however, but trsl::mp_weight_accessor which allows a default construction without implying segfault when called — that comes with a price, see trsl::mp_weight_accessor.
trsl::mp_weight_accessor<double, Particle>
&Particle::getWeight
(implicit conversion) The pointer to getWeight
implicitly constructs a trsl::mp_weight_accessor. (Why does the std counterpart have an explicit constructor?)
I had the impression that GCC was able to inline fuctions from pointers. Performance tests on accessors (see tests/accessor_efficiency.cpp
) tend to contradict this impression. With -03
optimization, the functor accessor is twice as fast as other accessors. Please comment if you know more about this.