我想计算各种语言(如Java,Python,Javascript)的代码执行时间。如何获取这些代码的执行时间?是否有可用于Python包或其他任何工具来通过传递文件(任何Java或Python文件)路径来计算执行时间?请分享您的建议。
我知道可以使用Python代码中的time模块来获取执行时间。如何在Python中执行Javascript和Java代码并在通用函数中获取执行时间?
我尝试了以下方法。
我知道可以使用Python代码中的time模块来获取执行时间。如何在Python中执行Javascript和Java代码并在通用函数中获取执行时间?
我尝试了以下方法。
import time
def get_exectime(file_path): # pass path of any file python,java,javascript, html, shell
start_time=time.time()
# execute the file given here. How to execute all file types here?
end_time=time.time()
exec_time=end_time-start_time
print(exec_time)
有没有其他方法可以实现这个目标?