Close

if you can cache a problem

A project log for faster speed: how Optimize math and process tasks

how to make math, and other processes faster for specific tasks on any processor. and logs of examples of math performance

jamesdanielvjamesdanielv 09/08/2019 at 13:000 Comments

 this method of boosting performance is universal. so it is probably one of the most effective ways to increase performance across designs, as it just reduces the amount redundant work. it does not use a specific syntax, or a special mode or method of a cpu design. all it uses is some variables outside of the loop.

there are times that a problem is solved more than one time. in some cases it is solved several times with the same results. there are also tables of data, that some data does not change. here is an example of a single function that can be called several times. the 2 values can be replaces with an array with reference to the cell it is being measured from. here is a basic view of how caching math works.

here is an example of a function that caches results. this is a simple version it only caches results if they are the same.

In order to cache data we need two values stored outside of the loop.

We need the ResultCache value. this is just a number we output without doing any further work

and we need the reference Compare Cached value. this is the value we use as a reference to verify that the problem has not changed.

here is an example function DataconvertDegCTodegF that takes a deg in c and changes it to deg in f.

We have several requests for this a second, but we never know how often it actually changes. several values are like this especially with sensors and data sets. many values are the same most of the time.

this is a simple example of Math caching.

float DataconvertDegCTodegF(float temperature_Deg_C ){//this value is read several times unknown interval of change

//we output a conversion to deg c from F

//(0°C × 9/5) + 32 = 32°F

if (reference_Compare_Cached_value !=float temperature_Deg_C ){

//we want to see if reference value has changed if it has we do work

ResultCache_value=(temperature_Deg_C *1.8)+32;//we get deg in F

reference_Compare_Cached_value ==temperature_Deg_C ;//we update reference 

}

//we have completed work if it changed, if not we send back what we have cached

return ResultCache_value;

}

this loop is not complex, but if it is ran several times a second it can have an impact on performance. some of the code i did for the amg8833 sensor used code for caching. 

Discussions