def _get_coordinates_of_stressed_proxy(self): highest_stress = LOWEST_STRESS if (len(self.proxies.keys() == 0)): raise ValueError(self.proxies) for coordinates, proxy in self.proxies.items(): stress_of_proxy = stress(proxy.LRUCache.cache_info()) if (stress_of_proxy > highest_stress): highest_stress = stress_of_proxy coordinates_of_stressed_proxy = coordinates return coordinates_of_stressed_proxy
import utils dict_cache = {} def dict_fibonacci(n): utils.validate_input(n) if n in (1, 2): return 1 if n not in dict_cache: dict_cache[n] = dict_fibonacci(n - 1) + dict_fibonacci(n - 2) return dict_cache[n] if __name__ == "__main__": utils.stress(["dict"], globals=globals())
# flake8: noqa from utils import stress from fib_dict import dict_fibonacci from fib_lru import lru_fibonacci from fib_bmemcached import bmemcached_fibonacci from fib_bmemcached import tls_bmemcached_fibonacci from fib_pymemcache import pymemcache_fibonacci from fib_pymemcache import tls_pymemcache_fibonacci prefixes = [ "dict", "lru", "bmemcached", "tls_bmemcached", "pymemcache", "tls_pymemcache", ] stress(prefixes=prefixes, globals=globals())
import utils from functools import lru_cache @lru_cache() def lru_fibonacci(n): utils.validate_input(n) if n in (1, 2): return 1 return lru_fibonacci(n - 1) + lru_fibonacci(n - 2) if __name__ == "__main__": utils.stress(["lru"], globals=globals())
def bmemcached_fibonacci(n): utils.validate_input(n) if n in (1, 2): return 1 f = client.get("b" + str(n)) if f is None: f = bmemcached_fibonacci(n - 1) + bmemcached_fibonacci(n - 2) client.set("b" + str(n), str(f)) return int(f) def tls_bmemcached_fibonacci(n): utils.validate_input(n) if n in (1, 2): return 1 f = tls_client.get("b" + str(n)) if f is None: f = tls_bmemcached_fibonacci(n - 1) + tls_bmemcached_fibonacci(n - 2) tls_client.set("b" + str(n), str(f)) return int(f) if __name__ == "__main__": utils.stress(["bmemcached", "tls_bmemcached"], globals=globals())
def pymemcache_fibonacci(n): utils.validate_input(n) if n in (1, 2): return 1 f = client.get("p" + str(n)) if f is None: f = pymemcache_fibonacci(n - 1) + pymemcache_fibonacci(n - 2) client.set("p" + str(n), str(f)) return int(f) def tls_pymemcache_fibonacci(n): utils.validate_input(n) if n in (1, 2): return 1 f = tls_client.get(str(n)) if f is None: f = tls_pymemcache_fibonacci(n - 1) + tls_pymemcache_fibonacci(n - 2) tls_client.set(str(n), str(f)) return int(f) if __name__ == "__main__": utils.stress(["pymemcache", "tls_pymemcache"], globals=globals())