Skip to content

Commit

Permalink
Add report_time.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 661668115
  • Loading branch information
mjanusz authored and copybara-github committed Aug 10, 2024
1 parent d9f24eb commit e5c1d04
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions connectomics/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
# limitations under the License.
"""Various utility functions."""

import contextlib
import itertools
import time

from absl import logging
import dataclasses_json
import numpy as np

Expand Down Expand Up @@ -79,3 +82,13 @@ class NPDataClassJsonMixin(dataclasses_json.DataClassJsonMixin):

def to_json(self, *args, **kw) -> str:
return super().to_json(*args, default=_handle_np, **kw)


@contextlib.contextmanager
def report_time(name):
start = time.time()
try:
yield
finally:
duration = time.time() - start
logging.info('time[%s] = %.6f', name, duration)

0 comments on commit e5c1d04

Please sign in to comment.