-
-
Save AlJohri/5c56ce1bd92e529978e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio, pymongo, random, time, traceback | |
from blessings import Terminal | |
t = Terminal() | |
import motor.motor_asyncio, pymongo | |
client = motor.motor_asyncio.AsyncIOMotorClient("mongodb://localhost:27017/test") | |
asyncdb = client.get_default_database() | |
async def main(): | |
await asyncdb.rand.drop() | |
for i in range(100000): | |
key = random.randint(1, 100000000) | |
obj = { "_id": key } | |
try: | |
await asyncdb.rand.insert(obj) | |
# print(t.green("{0} inserted into database".format(key))) | |
except pymongo.errors.DuplicateKeyError: | |
print(t.red("{0} already exists in database".format(key))) | |
except Exception as e: | |
traceback.print_stack() | |
import ipdb; ipdb.set_trace() | |
print(e) | |
start_time = time.time() | |
loop = asyncio.get_event_loop() | |
loop.set_debug(True) | |
loop.run_until_complete(main()) | |
loop.close() | |
end_time = time.time() | |
print(100000 / (end_time - start_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pip install aiohttp motor blessings