for i inrange(INSERT_COUNT): # insert l = [] for j inrange(EACH_INSERT): l.append(md5(str(i) + '_' + str(j))) pre = time.time() for k in l: sta = cur.execute("INSERT INTO `test_speed` (`value`) VALUES ('{0}')".format(k)) conn.commit() after = time.time() print("{0}: {1}".format(i, time.time() - pre)) insert_time = after - pre
# sort pre = time.time() cur.execute("SELECT * FROM test_speed ORDER BY value DESC limit 0, 10") after = time.time() print("sort time: {0}".format(time.time() - pre)) sort_time = after - pre
# search l = [] num = EACH_INSERT for k inrange(num): s = str(randint(0, i)) + '_' + str(randint(0, EACH_INSERT - 1)) l.append(md5(s)) pre = time.time() for k in l: cur.execute("SELECT * FROM test_speed WHERE value = '{0}'".format(k)) for v in cur: value = v[1] after = time.time() print("search time({0}): {1}".format(num, time.time() - pre)) search_time = after - pre
for i inrange(INSERT_COUNT): # insert l = [] for j inrange(EACH_INSERT): l.append(md5(str(i) + '_' + str(j))) pre = time.time() for k in l: collection.insert({'value': k}) after = time.time() print("insert time {0}: {1}".format(i, after - pre)) insert_time = after - pre
# sort pre = time.time() res = collection.find().sort('value', pymongo.DESCENDING).limit(10) after = time.time() print("sort time: {0}".format(after - pre)) sort_time = after - pre
# search l = [] num = EACH_INSERT for k inrange(num): s = str(randint(0, i)) + '_' + str(randint(0, EACH_INSERT - 1)) l.append(md5(s)) pre = time.time() for k in l: res = collection.find({'value': k}) for v in res: value = v['value'] after = time.time() print("search time({0}): {1}".format(num, after - pre)) search_time = after - pre