Yes your right, but I found that assigning
local_cache = cache.privateCache
by itself didn’t really help the lookup speeds at all. I guess it still has to lookup the .put and .get methods. I tried putting the loop section in a function to maximise local variable access.
At first, accessing the cache through local_cache.put / local_cache.get was even worse than my initial test of 3090ms, this one taking ~4400ms. But if you do one lookup of the .put and .get methods, and assign them to a local variable it greatly speeds up, now measuring ~1200ms.
def run_loop_cache(loops, local_cache, initial, _rate):
put = local_cache.put
get = local_cache.get
put('counter', initial)
for i in range(loops):
count = get('counter');
count = _rate*count*(1 - count);
put('counter', count);
run_loop_cache(100000, cache.privateCache, counter, rate)