def measure_elapsed_time():
    """
    Shows different ways to measure elapsed time in a sequence.

    You can measure time in milliseconds, microseconds, or seconds.

    Returns:
        int: time, in milliseconds, it took to run this sequence.

    """
    seqtime_timer = DoubleValue(0)
    seqtime_us_timer = I64Value(0)
    tick_ms_timer = I64Value(0)
    tick_us_timer = I64Value(0)

    # The following steps demonstrate different ways you can capture an initial timestamp:
    seqtime_timer.value = seqtime()
    seqtime_us_timer.value = seqtimeus()
    tick_ms_timer.value = tickcountms()
    tick_us_timer.value = tickcountus()

    # Simulates work to time.
    while iteration() < 1000:
        nivs_yield()

    # Measures the elapsed time by subtracting the initial timestamp from the current time.
    seqtime_timer.value = seqtime() - seqtime_timer.value
    seqtime_us_timer.value = seqtimeus() - seqtime_us_timer.value
    tick_ms_timer.value = tickcountms() - tick_ms_timer.value
    tick_us_timer.value = tickcountus() - tick_us_timer.value

    return tick_ms_timer.value
Exemplo n.º 2
0
def yield_multitask():
    with multitask() as mt:

        @task(mt)
        def f1():
            for a in range(5):
                nivs_yield()

        @task(mt)
        def f2():
            with multitask() as mt_inner:

                @task(mt_inner)
                def fa():
                    for b in range(7):
                        nivs_yield()

                @task(mt_inner)
                def fb():
                    for c in range(13):
                        nivs_yield()

    a = I32Value(0)
    a.value = iteration()
    return a.value
Exemplo n.º 3
0
def yield_many():
    a = I32Value(0)
    nivs_yield()
    nivs_yield()
    nivs_yield()
    nivs_yield()
    nivs_yield()
    a.value = iteration()
    return a.value
Exemplo n.º 4
0
def yield_in_while():
    a = I32Value(0)
    while a.value < 10:
        nivs_yield()
        a.value = iteration()
    return a.value
Exemplo n.º 5
0
def yield_single():
    a = I32Value(0)
    nivs_yield()
    a.value = iteration()
    return a.value