示例#1
0
def pqp_benchmark():
    task = Zeroes()
    # task = Lamb #Error: cant be pickled
    # task = Func
    batch_size = 16
    tensor_size = (9, 9, 9, 9, 9)
    wait_time = 0.1
    samples = 100

    df = PooledQueueProcessor(task,
                              args=[batch_size],
                              kwargs={"tensor_size": tensor_size},
                              max_queue_size=samples)

    def get():
        return df.get()

    def wait_get():
        time.sleep(wait_time)
        return df.get()

    def generate():
        return task(batch_size, tensor_size=tensor_size)

    def wait_generate():
        time.sleep(wait_time)
        return task(batch_size, tensor_size=tensor_size)

    for func, discount in zip(
        (get, wait_get, generate, wait_generate),
        (0, samples * wait_time, 0, samples * wait_time)):
        t, res = benchmark_func(func, samples)
        print(f"{func.__name__}: {t - discount} seconds")
示例#2
0
def returns_benchmark():
    """ """
    a = 1
    b = 2
    c = 3

    RandomABC = namedtuple("RandomABC", ("a", "b", "c"))

    def implicit_return():
        """ """
        return a, b, c

    def list_return():
        """ """
        return [a, b, c]

    def tuple_return():
        """ """
        return (a, b, c)

    def dict_return():
        """ """
        return {"a": a, "b": b, "c": c}

    def sorcery_return():
        """ """
        return sorcery.dict_of(a, b, c)

    def nod_return():
        """ """
        return NOD(a=a, b=b, c=c)

    def inferred_return():
        """ """
        return NOD.nod_of(a, b, c)

    def namedtuple_return():
        """ """
        return RandomABC(a, b, c)

    for func in (
        implicit_return,
        list_return,
        tuple_return,
        dict_return,
        namedtuple_return,
        nod_return,
        sorcery_return,
        inferred_return,
    ):
        t, res = benchmark_func(func)
        print(f"{func.__name__}: {t} seconds, {res}")
示例#3
0
def returns_benchmark() -> None:
    """
    :rtype: None
    """
    a = 1
    b = 2
    c = 3

    RandomABC = namedtuple("RandomABC", ("a", "b", "c"))

    def implicit_return() -> Tuple[int, int, int]:
        """
        :rtype: None
        """
        return a, b, c

    def list_return() -> List[int]:
        """
        :rtype: None
        """
        return [a, b, c]

    def tuple_return() -> Tuple[int, int, int]:
        """
        :rtype: None
        """
        return (a, b, c)

    def dict_return() -> Dict[str, int]:
        """
        :rtype: None
        """
        return {"a": a, "b": b, "c": c}

    def sorcery_return() -> None:
        """
        :rtype: None
        """
        return sorcery.dict_of(a, b, c)

    def nod_return() -> NamedOrderedDictionary:
        """
        :rtype: None
        """
        return NOD(a=a, b=b, c=c)

    def inferred_return() -> None:
        """
        :rtype: None
        """
        return NOD.nod_of(a, b, c)

    def namedtuple_return() -> RandomABC:
        """
        :rtype: None
        """
        return RandomABC(a, b, c)

    for func in (
            implicit_return,
            list_return,
            tuple_return,
            dict_return,
            namedtuple_return,
            nod_return,
            sorcery_return,
            inferred_return,
    ):
        t, res = benchmark_func(func)
        print(f"{func.__name__}: {t} seconds, {res}")