dautil.perf

class dautil.perf.CountMinSketch(depth=5, width=20, seed=28)

CountMin sketch implementation.

Variables:
  • depth – Depth of the CountMin sketch table.
  • width – Width of the CountMin sketch table.
  • table – The CountMin sketch table.
add(item)

Adds an item.

Parameters:item – An item.
estimate_count(item)

Estimates the count for an item.

Parameters:item – An item.
Returns:The estimated count.
hash(item, i)

Calculates the hash for a given item.

Parameters:
  • item – An item.
  • i – The index for which to compute the hash.
Returns:

The hash for the item.

class dautil.perf.LRUCache(impl, func, maxsize=128, typed=False)

Given a function and LRU caching implementation, caches the results of the function.

Variables:
  • impl – LRU cache implementation, for instance functools.lru_cache.
  • func – The function to cache.
  • maxsize – The size of the cache.
  • typed – Determines whether a distinction is made between arguments of different types.
  • cached – The cached function.
>>> from dautil import perf
>>> from functools import lru_cache
>>> cache = perf.LRUCache(lru_cache, lambda x: x)
>>> cache.cache()
>>> cache.cached(1)
1
>>> cache.cached(1)
1
>>> cache.hits_miss()
1.0
cache()

Caches the function.

clear()

Clears the cache.

get_info()

Gets cache info.

hits_miss()
Calculates hits/miss ratio.
In a muti-threaded environment, the calculation is approximate.
Returns:The hits/miss ratio.
class dautil.perf.StopWatch

A simple stopwatch, which has a context manager.

Variables:elapsed – Elapsed time in seconds.
>>> from dautil import perf
>>> with perf.StopWatch() as sw:
...     pass
...
>>> sw.elapsed
7.867813110351562e-06
dautil.perf.time_once(code, n=1)

Measures execution time of code (best of 3).

Parameters:
  • code – Code string or callable.
  • n – Number of times to repeat execution (n x 3).
Returns:

The best execution time.

Previous topic

dautil.options

Next topic

dautil.plotting

This Page