magland / ml_ms4alg

MountainSort v4
7 stars 19 forks source link

Improve performance for high-channel count #34

Open magland opened 3 years ago

magland commented 3 years ago

Here's a useful context manager for timing section of code:

import time

class Timer:
    def __init__(self, *, label='', verbose=False):
      self._label = label
      self._start_time = None
      self._stop_time = None
      self._verbose = verbose

    def elapsed(self):
      if self._stop_time is None:
        return time.time() - self._start_time
      else:
        return self._stop_time - self._start_time

    def __enter__(self):
      self._start_time = time.time()
      return self

    def __exit__(self, exc_type, exc_value, exc_tb):
      self._stop_time = time.time()
      if self._verbose:
        print(f"Elapsed time time for {self._label}: {self.elapsed()} sec")

with Timer(label='sleep', verbose=True) as timer:
  # some expensive operation
  time.sleep(3)

print(timer.elapsed())
magland commented 3 years ago

Run mountainsort4 on 18-ch recording, 10-60 minutes. And try to determine where the bottleneck is:

This is the file you'll need to put thing timing tests: https://github.com/magland/ml_ms4alg/blob/master/ml_ms4alg/ms4alg.py

magland commented 3 years ago

Different parts to time:

Also useful to know the scaling properties of the above steps (as channel number or duration increases)

I suggest trying duration: 10 minutes, 20 minutes (compare timings) channel count: 9, 18 (compare timings)

magland commented 3 years ago

May also be helpful to see how timings scale with changes in adjacency_radius (nbhd size).