本文整理汇总了Python中timer.Timer.get_seconds方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.get_seconds方法的具体用法?Python Timer.get_seconds怎么用?Python Timer.get_seconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.get_seconds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collectionQuery3
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import get_seconds [as 别名]
def collectionQuery3():
totalRuns = config.executions
connection = pymysql.connect(**config.dbConfig)
cursor = connection.cursor()
percentConfig = totalRuns / 100
timer = Timer()
meanTime = 0
limit = 20
print("=================================== Collection Query 3 ===================================")
print(" SELECT text_id AS id, p_text AS text, p_published AS published FROM tag_query3 LEFT JOIN text ON text_id = text.id WHERE p_country = 1 p_type = 'postType' AND p_rank < `postRank` AND p_site = 'site' ORDER BY p_rank DESC LIMIT 20;")
for run in range(totalRuns):
postType = config.postTypes[randint(0, 9)]
postRank = randint(1, config.totalPosts - 1)
country = config.countries[randint(0, 3)]
site = config.siteConfig[randint(0, 19)]
query = "SELECT text_id AS id, p_text AS text, p_published AS published FROM tag_query3 LEFT JOIN text ON text_id = text.id WHERE p_{} = 1 AND p_type = '{}' AND p_rank < {} AND p_site = '{}' ORDER BY p_rank DESC LIMIT {}".format(country, postType, postRank, site, limit)
timer.restart()
cursor.execute(query)
meanTime += timer.get_seconds()
percent = (run / totalRuns) * 100
if (run % percentConfig) == 0:
print("Completed: {:.0f} % ".format(percent), end = '\r')
print("Completed 100 %")
print("Mean query execution time : {:.10f} seconds".format(meanTime / totalRuns))
connection.close()
print("")
print("Example Query")
print(query)
print("")
return meanTime / totalRuns
示例2: getPostById
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import get_seconds [as 别名]
def getPostById():
totalRuns = config.executions
connection = pymysql.connect(**config.dbConfig)
cursor = connection.cursor()
timer = Timer()
meanTime = 0
percentConfig = totalRuns / 100
print("==================================== Post By Id Query ====================================")
print("SELECT obj FROM wp_posts WHERE id = post_id;")
for run in range(totalRuns):
postId = randint(1, config.totalPosts)
query = "SELECT {} FROM wp_posts WHERE id = {}".format('text', postId)
timer.restart()
cursor.execute(query)
meanTime += timer.get_seconds()
percent = (run / totalRuns) * 100
if (run % percentConfig) == 0:
print("Completed: {:.0f} % ".format(percent), end = '\r')
print("Completed 100 %")
print("Mean query execution time : {:.10f} seconds".format(meanTime / totalRuns))
connection.close()
print("")
print("Example Query")
print(query)
print("")
return meanTime / totalRuns
示例3: collectionQuery2
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import get_seconds [as 别名]
def collectionQuery2():
fake = Faker()
totalRuns = config.executions
connection = pymysql.connect(**config.dbConfig)
cursor = connection.cursor()
limit = 20
timer = Timer()
meanTime = 0
percentConfig = totalRuns / 100
tags = []
config.getTags(tags)
print("=================================== Collection Query 2 ===================================")
print("SELECT text_id AS id, p_text AS text FROM wp_tags AS t LEFT JOIN post2tag ON t.id = tag_id LEFT JOIN tag_query2 ON post_id = text_id LEFT JOIN text ON text_id = text.id WHERE t.name = 'tagName' AND p_site = 'site' AND p_country = 1 AND p_rank < rank ORDER BY p_rank DESC LIMIT 20")
for run in range(totalRuns):
tagName = tags[randint(0, config.totalTags - 1)]
postRank = randint(1, config.totalPosts)
site = config.siteConfig[randint(0, 19)]
country = config.countries[randint(0, 3)]
query = "SELECT text_id AS id, p_text AS text FROM wp_tags AS t LEFT JOIN post2tag ON t.id = tag_id LEFT JOIN tag_query2 ON post_id = text_id LEFT JOIN text ON text_id = text.id WHERE t.name = '{}' AND p_site = '{}' AND p_{} = 1 AND p_rank < {} ORDER BY p_rank DESC LIMIT {}".format(tagName, site, country, postRank, limit)
timer.restart()
cursor.execute(query)
meanTime += timer.get_seconds()
percent = (run / totalRuns) * 100
if (run % percentConfig) == 0:
print("Completed: {:.0f} % ".format(percent), end = '\r')
print("Completed 100 %")
print("Mean query execution time : {:.10f} seconds".format(meanTime / totalRuns))
connection.close()
print("")
print("Example Query")
print(query)
print("")
return meanTime / totalRuns