本文整理汇总了Python中timer.Timer.print_elapsed方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.print_elapsed方法的具体用法?Python Timer.print_elapsed怎么用?Python Timer.print_elapsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.print_elapsed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_all_words
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import print_elapsed [as 别名]
def read_all_words():
"""Return an unsorted list of all words to process."""
words = []
timer = Timer()
text = open("/usr/share/dict/words").read()
timer.print_elapsed("Reading words file")
timer = Timer()
lines = text.split("\n")
timer.print_elapsed("Splitting words file")
timer = Timer()
for word in lines:
# Get rid of \n
word = word.strip()
# Skip capitalized words. Here we should also skip words with hyphens
# and other symbols, but our dictionary doesn't have any anyway.
if word and word[0].islower():
# We work entirely in upper case.
word = word.upper()
# Skip short words.
if len(word) >= 3:
words.append(word)
timer.print_elapsed("Processing %d words" % len(lines))
return words
示例2: main
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import print_elapsed [as 别名]
def main():
size = 4
# Try these classes.
classes = [
trie_dictionary.TrieDictionary,
prefix_dictionary.PrefixDictionary,
binary_search_dictionary.BinarySearchDictionary,
progressive_binary_search_dictionary.ProgressiveBinarySearchDictionary,
progressive_text_binary_search_dictionary.ProgressiveTextBinarySearchDictionary,
]
# Read the dictionary from disk.
timer = Timer()
words = read_all_words()
timer.print_elapsed("Reading all words")
# Create each of the dictionaries.
dictionaries = []
for cls in classes:
timer = Timer()
dictionaries.append(cls.make_dictionary(words))
timer.print_elapsed("Creating %s" % cls.__name__)
# Generate a random board.
board = generate_board(size)
print_board(board, size)
# Solve the board using each of the dictionaries. We solve the board multiple
# times to reduce noise.
solutions = []
for dictionary in dictionaries:
timer = Timer()
for i in range(20):
solution = solve_board(board, size, dictionary)
timer.print_elapsed("Solving with %s" % dictionary.__class__.__name__)
solutions.append(solution)
# Compare each dictionary solution to the first one to make sure we're implementing
# these right.
for i in range(1, len(solutions)):
if solutions[0] != solutions[i]:
print "In %s but not in %s: %s" % (
classes[0].__name__,
classes[i].__name__,
", ".join(sorted(solutions[0].difference(solutions[i]))))
print "In %s but not in %s: %s" % (
classes[i].__name__,
classes[0].__name__,
", ".join(sorted(solutions[i].difference(solutions[0]))))
print "All words: " + ", ".join(sorted(solutions[0]))