Skip to main content

TimeIt Resource to easily capture and report time consumed by code snippets.

Project description

timeit_resource

timeit_resource: Python Resource to easily capture and report time consumed by code snippets.

Here is the GitHub repo:

Here is the pip command to install it:

pip install timeit_resource

Here’s a simple example of how you might use timeit_resource:

  # Write time elapsed information to stdout, with default title (prefix)
  with TimeIt() as timer:
    # Your time-consuming code here
    for _ in range(1000000):
      pass

Here are examples that further explore using timeit_resource:

  TimeIt.prefix = '  '
  
  # Write to stdout, nested
  with TimeIt("Total time taken"):
    from time import sleep
    for _ in range(10):
      with TimeIt("Time taken - outer"):
        for _ in range(10):
          with TimeIt("Time taken - inner"):
            sleep(0.01)


  # Append to output.txt
  with TimeIt(title="Time taken", output="output.txt") as t:
    # Your time-consuming code here
    for _ in range(1000000):
      pass

  # Write to stderr
  with TimeIt(output=sys.stderr) as t:
    # Your time-consuming code here
    for _ in range(1000000):
      pass

  # Write to an output stream that the client owns!
  with open("output.txt", 'w') as f:
    with TimeIt(output=f) as t:
      # Your time-consuming code here
      for _ in range(1000000):
        pass

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timeit_resource-0.0.1.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

timeit_resource-0.0.1-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page