import time
from concurrent.futures import ProcessPoolExecutor

import snek.serpentarium

durations = []


def task1():
    global durations
    client = snek.serpentarium.DatasetWrapper()

    start = time.time()
    for x in range(1500):

        client["a"].delete()
        client["a"].insert({"foo": x})
        client["a"].find(foo=x)
        client["a"].find_one(foo=x)
        client["a"].count()
        # print(client['a'].find(foo=x) )
        # print(client['a'].find_one(foo=x) )
        # print(client['a'].count())
    client.close()
    duration1 = f"{time.time()-start}"
    durations.append(duration1)
    print(durations)


with ProcessPoolExecutor(max_workers=4) as executor:
    tasks = [
        executor.submit(task1),
        executor.submit(task1),
        executor.submit(task1),
        executor.submit(task1),
    ]
    for task in tasks:
        task.result()


import dataset

client = dataset.connect("sqlite:///snek.db")
start = time.time()
for x in range(1500):

    client["a"].delete()
    client["a"].insert({"foo": x})
    print([dict(row) for row in client["a"].find(foo=x)])
    print(dict(client["a"].find_one(foo=x)))
    print(client["a"].count())
duration2 = f"{time.time()-start}"

print(duration1, duration2)
