Я написал код для проблемы HackerRank (https://www.hackerrank.com/challenges/acm-icpc-team).Время выполнения с использованием time.time() в Python
import time
from itertools import combinations
start_time = time.time()
n,m = raw_input().strip().split(' ') # n = no of people and m = no of topics
n,m = [int(n),int(m)]
topic = []
topic_i = 0
for topic_i in xrange(n):
topic_t = str(raw_input().strip())
topic.append(topic_t) # populate the topic[] list with the topics
counts = []
for list1, list2 in combinations(topic, 2):
if list1 != list2:
count = 0
for i in xrange(m):
if int(list1[i]) | int(list2[i]):
count += 1
counts.append(count)
print max(counts)
print counts.count(max(counts))
print time.time() - start_time
Когда я пытаюсь запустить код, я получаю время выполнения 8.37576699257
секунд. Но моя программа закончилась в одно мгновение. Я прочитал, что функция timeit()
по умолчанию запускает функцию, переданную ей миллион раз. Что-то подобное происходит здесь?
Хорошо, буду использовать его в следующий раз, когда захочу, чтобы программа была моей. –