# Path: benchmarks/utils.py
# def log_time(name):
#     def wrapper(func):
#         def run(*args, **kwargs):
#             start = time.time()
#             res = func(*args, **kwargs)
#             print('The execution time of {}: {}'.format(name, time.time() - start))
#             return res
# 
#         return run
# 
#     return wrapper


import random
from queue import PriorityQueue
from heapq import heappush, heappop
from benchmarks.utils import log_time

@log_time('prepare benchmark data')
def prepare_benchmark_data(push_rate=0.5, total=0):
    data = []
    n = 0
    while len(data) + n < total:
        r = random.random()
        if n == 0 or r < push_rate:
            data.append(('push', random.randint(0, 2147483647)))
            n += 1
        else:
            data.append(('pop', None))
            n -= 1
    while n > 0:
        data.append(('pop', None))
        n -= 1
    return data


@log_time('system priority queue')
def benchmark_system_priority_queue(data):
    q = PriorityQueue()
    for d in data:
        op, v = d
        if op == 'push':
            q.put_nowait(v)
        else:
            q.get_nowait()



# Path: benchmarks/utils.py
# def log_time(name):
#     def wrapper(func):
#         def run(*args, **kwargs):
#             start = time.time()
#             res = func(*args, **kwargs)
#             print('The execution time of {}: {}'.format(name, time.time() - start))
#             return res
# 
#         return run
# 
#     return wrapper


# Path: benchmarks/priority_queue_benchmark.py
import random
from queue import PriorityQueue
from heapq import heappush, heappop
from benchmarks.utils import log_time


@log_time('prepare benchmark data')
def prepare_benchmark_data(push_rate=0.5, total=0):
    data = []
    n = 0
    while len(data) + n < total:
        r = random.random()
        if n == 0 or r < push_rate:
            data.append(('push', random.randint(0, 2147483647)))
            n += 1
        else:
            data.append(('pop', None))
            n -= 1
    while n > 0:
        data.append(('pop', None))
        n -= 1
    return data


@log_time('system priority queue')
def benchmark_system_priority_queue(data):
    q = PriorityQueue()
    for d in data:
        op, v = d
        if op == 'push':
            q.put_nowait(v)
        else:
            q.get_nowait()



@log_time('list heap priority queue')