Python所需的时间

Python所需的时间,python,python-3.x,Python,Python 3.x,我试图使用python解决此链接上的问题: https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/tds-and-his-breakup/ 我用两种方法解决了这个问题: 1. 2. 为什么第一种方法所需的时间和内存大于第二种方法,尽管第二个是使用列表来存储输入,并对输入进行两次迭代?您是否使用hacker ear

我试图使用python解决此链接上的问题:

https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/tds-and-his-breakup/
我用两种方法解决了这个问题:

1. 2.
为什么第一种方法所需的时间和内存大于第二种方法,尽管第二个是使用列表来存储输入,并对输入进行两次迭代?

您是否使用hacker earth上的内置时间/内存结果来判断哪一个更快/使用更少内存?我不知道为什么这很重要,但是我相信第二个版本更快的原因是所有的
输入
调用都在一起,所有的
打印
调用都在一起,而在第一个版本中,
输入
打印
调用是交错的。它可能是等待清除的std out缓冲区,并在执行时干扰std in?有人对此提交有相同的问题。一个答案是“列表存储在辅助内存中,不会影响缓存/主内存大小。而同时读取和操作传入数据只使用缓存/主内存。这里计算缓存/主内存的大小。如果我错了,请纠正我。”我对python内存不够熟悉,无法判断这是否正确。
n = int(input())
min_skill = int(input())

for i in range(n):
    if int(input()) >= min_skill:
        print("YES")
    else:
        print("NO")
n = int(input())
min_skill = int(input())
list_skill = []

for i in range(n):
    temp = int(input())
    list_skill.append(temp)

for skill in list_skill:
    if skill >= min_skill:
        print("YES")
    else:
        print("NO")