<#1581 Measuring the time taken for each component...
# flyte-github
a
#1581 Measuring the time taken for each component when executing a task Pull request opened by Yicheng-Lu-llll TL;DR The concept involves measuring the time taken by each component when executing a task, including both Flytekit and user-defined parts. Users have the option to view a timeline graph by setting the
disable_deck parameter=False
. For example:
Copy code
from flytekit import task, Resources, workflow
from flytekit.core.utils import timeit


@task(
    disable_deck=False,
    limits=Resources(mem="4Gi", cpu="1"),
)
def t1():
    import time

    # Test timeit used as a decorator
    @timeit("Download data from s3")
    def download_data():
        time.sleep(1)

    download_data()

    # Test timeit used as a context manager
    # Simulate a user using a very long name for a time measurement
    with timeit("Test long string "*20):
        time.sleep(1)

    # Simulate multiple time measurements
    for i in range(10):
        with timeit(f"Run small tasks {i}"):
            # The 'print' function will execute quickly compared to 'time.sleep(1)'.
            # This is used to test if the timeline graph can accurately represent
            # measurements with significantly varying execution times.
            print("hello world")     


@workflow
def wf():
    t1()

if __name__ == "__main__":
    wf()
Tests(also tested in sandbox):

image

image

image

Note: • Setting the disable_deck parameter to True will only affect whether the user can see the timeline graph(whether HTML generated). The data will still be collected and stored in the background. However, for input and output decks, if the disable_deck parameter is set to True, these decks will not be created at all. Type ☐ Bug Fix ☑︎ Feature ☐ Plugin Are all requirements met? ☐ Code completed ☐ Smoke tested ☐ Unit tests added ☐ Code documentation added ☐ Any pending items have an associated Issue Complete description How did you fix the bug, make the feature etc. Link to any design docs etc flyteorg/flytekit Codecov: 69.60% of diff hit (target 70.12%) 29 other checks have passed 29/30 successful checks