code: def _format_time(timespan, precision=3):
      """Formats the timespan in a human readable form"""
      import math
  
      if timespan >= 60.0:
          # we have more than a minute, format that in a human readable form
          # Idea from http://snipplr.com/view/5713/
          parts = [
              ("d", 60 * 60 * 24),
              ("h", 60 * 60),
              ("min", 60),
              ("s", 1),
          ]
          time = []
          leftover = timespan
          for suffix, length in parts:
              value = int(leftover / length)
              if value > 0:
                  leftover = leftover % length
                  time.append("%s%s" % (str(value), suffix))
              if leftover < 1:
                  break
          return " ".join(time)
  
      # Unfortunately the unicode 'micro' symbol can cause problems in
      # certain terminals.
      # See bug: https://bugs.launchpad.net/ipython/+bug/348466
      # Try to prevent crashes by being more secure than it needs to
      # E.g. eclipse is able to print a µ, but has no sys.stdout.encoding set.
      units = ["s", "ms", "us", "ns"]  # the save value
      if hasattr(sys.stdout, "encoding") and sys.stdout.encoding:
          try:
              "\xb5".encode(sys.stdout.encoding)
              units = ["s", "ms", "\xb5s", "ns"]
          except:
              pass
      scaling = [1, 1e3, 1e6, 1e9]
  
      if timespan > 0.0:
          order = min(-int(math.floor(math.log10(timespan)) // 3), 3)
      else:
          order = 3
      return "%.*g %s" % (
          precision,
          timespan * scaling[order],
          units[order],
      )
  
imports: from __future__ import print_function
  from __future__ import absolute_import
  import ast
  import bdb
  import gc
  import itertools
  import os
  import sys
  import time
  import timeit
  from pdb import Restart
  from IPython.core import oinspect
  from IPython.core import magic_arguments
  from IPython.core import page
  from IPython.core.error import UsageError
  from IPython.core.macro import Macro
  from IPython.core.magic import Magics, magics_class, line_magic, cell_magic, line_cell_magic, on_off, needs_local_scope
  from IPython.testing.skipdoctest import skip_doctest
  from IPython.utils import py3compat
  from IPython.utils.py3compat import builtin_mod, iteritems, PY3
  from IPython.utils.contexts import preserve_keys
  from IPython.utils.capture import capture_output
  from IPython.utils.ipstruct import Struct
  from IPython.utils.module_paths import find_mod
  from IPython.utils.path import get_py_filename, shellglob
  from IPython.utils.timing import clock, clock2
  from warnings import warn
  from logging import error
label_desc: Use image node_id 2 for calling a global function with example usage: _format_time(timespan, precision) and returns: unknown, str