Faster version of double_price to int_price given the input sequence
In a given trading system, the input prices are of type double
. The minimum_price_increment min_price_increment_
is known, and equality is defined as :
inline bool DblPxCompare ( const double & price1, const double & price2 ) const
{
register double tdiff = ( price1 - price2 );
return ( ( tdiff > -half_min_price_increment_ ) &&
( tdiff < half_min_price_increment_ ) ) ;
}
An implementation of DblToInt :
inline int DblPxToIntPx ( const double & price ) const
{
return ( ( int ) round ( price / min_price_increment_ ) ) ;
}
But prices tend to be bunched up, as in typically a point in time orders tend to be sent at similar prices. Could we d开发者_运维百科o better, for instance by keeping a sorted list of last 20 conversions from Double Price to Int Price ?
I'd be inclined to say no, caching is not going to work better. The reason is that each time you'll need to check that the entries in the cache are appropriate for the conversion at hand, and I think that check is going to negate any performance advantage from saving having to do the conversion in the first place. What you already have is, IMHO, not complex enough to benefit from caching.
精彩评论