저는 C++로 제 첫 프로그램 중 하나를 컴파일했습니다. 그런 다음 파이썬에서 동일한 프로그램을 따라 실행했습니다 (아직 C++의 명령문을 찾지 못했습니다). 파이썬 프로그램은 두 배의 속도였습니다. 나는 항상 C++과 다른 컴파일 언어가 훨씬 빨랐다는 인상을 받았다. 여기에 프로그램이 있습니다. 아마도 나는 잘못된 것을하고 있습니다.C++ 파이썬보다 천천히? 이것이 어떻게 가능한지?
def main():
num1 = int(input('Enter an integer: '))
num2 = int(input('Enter another integer: '))
if num1 > num2:
while num1 >= num2:
print(num1)
num1 -= 1
else:
while num2 >= num1:
print(num2)
num2 -=1
main()
#include <iostream>
int main()
{
int num1 = 0, num2 = 0;
std::cout << "Enter an integer: ";
std::cin >> num1;
std::cout << "Enter another integer: ";
std::cin >> num2;
std::cout << std::endl;
while (num1 >= num2) {
std::cout << num1 << std::endl;
--num1;
}
system("pause>nul");
return 0;
}
'std :: endl'을' '\ n''로 바꾸십시오. – tom
어떻게 시간을 측정 했습니까? 두 가지 모두 입력으로 어떻게 보냈습니까? – 0x90
@tom std :: endl은 '\ n'으로 대체하면 안됩니다. –