简体   繁体   English

在程序结束之前估算Java程序的执行时间

[英]Estimate the execution time of java program before program ends

I was wondering how can I estimate a total running time of a java program on specific machine before program ends? 我想知道如何才能在程序结束之前估算特定机器上的Java程序总运行时间? I need to know how much it will take so I can announce the progress by that. 我需要知道需要多少时间,这样我才能宣布进度。

FYI Main algorithm of my program takes O(n^3) time complexity. FYI我程序的主要算法需要O(n ^ 3)时间复杂度。 Suppose n= 100000, how much it takes to run this program on my machine? 假设n = 100000,在我的机器上运行该程序需要多少时间? (dual intel xeon e2650) (双Intel Xeon E2650)

Regards. 问候。

In theory 1GHz of computational power should result in about 1 billion simple operations. 理论上,1 GHz的计算能力将导致大约10亿次简单运算。 However finding the number of simple operations is not always easy. 但是,找到简单操作的数量并不总是那么容易。 Even if you know the time complexity of a given algorithm, this is not enough - you also need to know the constant factor. 即使您知道给定算法的时间复杂度,这还远远不够-您还需要知道常数因子。 In theory it is possible to have a linear algorithm that takes several seconds to compute something for input of size 10000 (and some algorithms like this exist - like the linear pre-compute time RMQ). 从理论上讲,可以有一种线性算法,该算法需要花费几秒钟的时间来计算大小为10000输入(某些类似的算法存在-例如线性预计算时间RMQ)。

What you do know, however is that something of O(n^3) will need to perform on the order of 100000^3 operations. 但是,您所知道的是,将需要执行O(n^3)的数量级为100000^3操作。 So even if your constant is about 1/10^6 (which is highly unprobable), this computation will take a lot of time. 因此,即使您的常数约为1/10^6 (极不可能),此计算也将花费大量时间。

I believe @ArturMalinowski 's proposal is the right way to approach your problem. 我相信@ArturMalinowski的提案是解决您的问题的正确方法。 If you benchmark the performance of your algorithm for some sequence known aforehand eg {32,64,128,...} or as he proposes {1,10,100,...} . 如果您针对预先已知的某个序列(例如{32,64,128,...}或他建议的{1,10,100,...}对算法的性能进行基准测试。 This way you will be able to determine the constant factor with relatively good precision. 这样,您将能够以相对较高的精度确定常数因子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM