Stash `util.print_runtime` to measure performance
"""This module provides general utility methods."""
-
+from contextlib import contextmanager
from functools import lru_cache, wraps
import locale
import logging
@@ -8,6 +8,8 @@ import os
import re
import sublime
import subprocess
+import time
+import threading
if False:
@@ -32,6 +34,16 @@ def printf(*args):
print()
+@contextmanager
+def print_runtime(message):
+ start_time = time.perf_counter()
+ yield
+ end_time = time.perf_counter()
+ duration = round((end_time - start_time) * 1000)
+ thread_name = threading.current_thread().name[0]
+ print('{} took {}ms [{}]'.format(message, duration, thread_name))
+
+
def show_message(message, window=None):
if window is None:
window = sublime.active_window()
