
On Behalf Of Matthew Hurd Subject: [boost] [named_params] timing trivia and some comments
Been looking at the very cute named_params in the sandbox. Getting around to trying to do some stuff with it.
Noticed something interesting w.r.t. vc7.1 optimization:
BOOST_NAMED_PARAMS_FUN(double, power, 0, 2, power_keywords ) { double b = p[base | 10]; double e = p[exponent | 1]; return pow(b ,e); }
double pow_wrap(double b, double e) { return pow(b,e); }
are the same speed, around 25 nanoseconds on my machine, when called with some variable parameters ( now = pow_wrap(t.elapsed(),t.elapsed() / (rand() * t.elapsed())); ) to defeat the chance of variable elimination and constant propagation.
But interestingly,
BOOST_NAMED_PARAMS_FUN(double, power, 0, 2, power_keywords ) { return pow(p[base | 10] , p[exponent | 1]); }
is more than five times slower at 144 nanoseconds.
FWIW, Calling power(exponent = t.elapsed() / (rand() * t.elapsed()), base= t.elapsed() ); That is, with the parameters in the reverse order to the natural order, takes nearly twice as long with this configuration, so there seems a little penalty for being out of order with this example, compiler, hardware and OS. Not sure it means anything much though. Regards, Matt Hurd. ________________________________________ ---------------------------------------------------------------------------- ---- looper invasive timing estimate simple_named_params ---------------------------------------------------------------------------- ---- median time = 52.15311004785687 nanoseconds 90% range size = 0.4784688995215372 nanoseconds widest range size (max - min) = 10.32153110047848 microseconds minimum time = 46.41148325358853 nanoseconds maximum time = 10.36794258373207 microseconds 50% range = (52.15311004785686 nanoseconds, 52.15311004785688 nanoseconds) 50% range size = 3.308722450212111e-014 nanoseconds ---------------------------------------------------------------------------- ---- looper invasive timing estimate simple_wrap ---------------------------------------------------------------------------- ---- median time = 24.88038277512962 nanoseconds 90% range size = 3.308722450212111e-015 nanoseconds widest range size (max - min) = 10.3464114832536 microseconds minimum time = 24.88038277511962 nanoseconds maximum time = 10.37129186602872 microseconds 50% range = (24.88038277512962 nanoseconds, 24.88038277512962 nanoseconds) 50% range size = 0 nanoseconds