PYTHON与JAVA执行时间对比
- PYTHON
- JAVA
- 结论
PYTHON
import timestart_time = time.time()n = int(input())
jie = 1
sum = 0
i = 1
while n >= i:jie = jie * isum = sum + jiei = i + 1
print(sum)end_time = time.time()print("程序执行时间为:", end_time - start_time, "秒")
执行结果
程序执行时间为: 0.00101470947265625 秒
JAVA
public static void main(String[] args) {double st = System.nanoTime() / 1000000000.0;long jie = 1;long sum = 0;for (int i = 1; i <= 4000; i++) {jie = jie * i;sum = sum + jie;}System.out.println(sum);double et = System.nanoTime() / 1000000000.0;System.out.println("程序执行时间为:" + (et - st) + "秒");}
执行结果
程序执行时间为:1.868999097496271E-4秒
结论
JAVA的执行要比PYTHON快。