Beispiel #1
0
def main():

    stopwatch = aiocells.Stopwatch()
    graph = create_graph(stopwatch)

    asyncio.run(aiocells.async_compute_concurrent(graph))
    print("Computation with async_compute_concurrent took"
          f" {stopwatch.elapsed_time()}")
Beispiel #2
0
def main():

    graph = aiocells.DependencyGraph()

    time = aiocells.Place()

    # 'aio.timer' will put the current time in the 'time' variable when
    # one second has expired
    timer = functools.partial(aiocells.timer, 1, time)
    printer = aiocells.print_value(time, "variable changed to {value}")

    graph.add_precedence(timer, time)
    graph.add_precedence(time, printer)
    logger.debug("graph: %s", graph)

    logger.info("First computation...")
    asyncio.run(aiocells.async_compute_concurrent(graph))
    logger.debug("graph: %s", graph)

    logger.info("Second computation...")
    asyncio.run(aiocells.async_compute_concurrent(graph))
    logger.debug("graph: %s", graph)
Beispiel #3
0
def main():

    graph = aiocells.DependencyGraph()

    time = aiocells.Place()
    timer = TimerObject(time)

    # Here, we bind the coroutine method with the object
    compute_timer = functools.partial(TimerObject.compute, timer)
    printer = aiocells.print_value(time, "variable changed to {value}")

    graph.add_precedence(compute_timer, time)
    graph.add_precedence(time, printer)
    logger.debug("graph: %s", graph)

    logger.info("First computation...")
    asyncio.run(aiocells.async_compute_concurrent(graph))
    logger.debug("graph: %s", graph)

    logger.info("Second computation...")
    asyncio.run(aiocells.async_compute_concurrent(graph))
    logger.debug("graph: %s", graph)
Beispiel #4
0
def main():

    stopwatch = aiocells.Stopwatch()
    graph = create_graph(stopwatch)

    print("Should take about 3 seconds...")
    asyncio.run(aiocells.async_compute_concurrent_simple(graph))
    print("Computation with `async_compute_concurrent_simple` took "
          f"{stopwatch.elapsed_time()}")

    print("Should take about 3 seconds...")
    asyncio.run(aiocells.async_compute_concurrent(graph))
    print("Computation with `async_compute_concurrent` took "
          f"{stopwatch.elapsed_time()}")
Beispiel #5
0
def main():
    stopwatch = aiocells.Stopwatch()
    graph = demo_6.create_graph(stopwatch)

    # Here, we run the same graph as the previous demo but we use
    # 'async_compute_concurrent' which will run the two sleeps concurrently.
    # Thus, the execution time will be around 2 seconds, the maximum of
    # the two sleeps.

    print("Running previous demo's graph concurrently.")
    print("Total execution time should be about 2 seconds...")
    asyncio.run(aiocells.async_compute_concurrent(graph))
    print("Computation with `async_compute_concurrent` took"
          f" {stopwatch.elapsed_time()}")
Beispiel #6
0
def main():

    stopwatch = aiocells.Stopwatch()
    graph = create_graph(stopwatch)

    # How long does it take to compute 100000 null callables with
    # async_compute_concurrent_simple?
    asyncio.run(aiocells.async_compute_concurrent_simple(graph))
    print("Computation with async_compute_concurrent_simple took"
          f"{stopwatch.elapsed_time()}")

    # How long does it take to compute 100000 null callables with
    # async_compute_concurrent?
    asyncio.run(aiocells.async_compute_concurrent(graph))
    print("Computation with async_compute_concurrent took"
          f" {stopwatch.elapsed_time()}")
Beispiel #7
0
def main():

    stopwatch = aiocells.Stopwatch()
    graph = create_graph(stopwatch)

    # How long does it take to run 100000 async 1 second sleeps with
    # async_compute_concurrent_simple?
    print("Running 100000 async 1 second sleeps with"
          " async_compute_concurrent_simple...")
    asyncio.run(aiocells.async_compute_concurrent_simple(graph))
    print("Computation with `async_compute_concurrent_simple` took"
          f" {stopwatch.elapsed_time()}")

    # How long does it take to run 100000 async 1 second sleeps with
    # async_compute_concurrent?
    print("Running 100000 async 1 second sleeps with"
          " async_compute_concurrent...")
    asyncio.run(aiocells.async_compute_concurrent(graph))
    print("Computation with `async_compute_concurrent` took"
          f" {stopwatch.elapsed_time()}")