【发布时间】:2019-08-25 00:54:42
【问题描述】:
我正在尝试计算我的算法性能。基本上我的算法解决了集合操作,如联合、析取、交集等。我的算法可以在 O(logn) 中完成这些操作,以与类似的算法进行比较计算运行时间我看到其他算法中的一些操作实际上需要 0(零)纳秒来完成。通过操作,我的意思是找到两个集合的并集,每个集合中有 10000 个元素。这怎么可能?你可以在Github 上看到我的项目。 我计算运行时间的部分在测试包中
我尝试使用 Jprofilier 来确保它全部在一个线程上运行
我尝试在 to 时间间隔之间进行调试,以确保它不会忽略计算并找到正确的结果
static Duration IntersectDocumentsTime(AlgorithmInterface algorithm)
{
Instant start = Instant.now(); // Time before calulation i tryed to put breakpoint here
algorithm.IntersectDocuments(); // returns Term[] result of elements after union operation
Instant end = Instant.now(); // Time after calulation
return Duration.between(start,end); // i put a breakpoint here to see if IntersectDocuments() result is correct and actually calculated
}
这就是我打印结果的方式
for (AlgorithmInterface al: Algorithms)
{
System.out.println("------------------------------------------------------------------------------");
System.out.println("Algorithm: "+al.getClass().toString()+"\tOperation: Union\nTime: "
+OperationsInterface.AddDocumentsTime(al).toNanos()+"\tseconds");
System.out.println("Algorithm: "+al.getClass().toString()+"\tOperation: Disjuction\nTime: "
+OperationsInterface.DisjointDocumentsTime(al).toNanos()+"\tseconds");
System.out.println("Algorithm: "+al.getClass().toString()+"\tOperation: Intersection\nTime: "
+OperationsInterface.IntersectDocumentsTime(al).toNanos()+"\tseconds");
System.out.println("Algorithm: "+al.getClass().toString()+"\tOperation: Subtraction\nTime: "
+OperationsInterface.SubtractDocumentsTime(al).toNanos()+"\tseconds");
System.out.println("Algorithm: "+al.getClass().toString()+"\tOperation: Find\nTime: "
+OperationsInterface.ContainsTermTime(al,new Term("A")).toNanos()+"\tseconds");
}
System.out.println("------------------------------------------------------------------------------");
结果如下所示
算法:类 Algorithms.FNA.FNA 操作:联合 时间:1851133600秒 算法:类 Algorithms.FNA.FNA 运算:析取 时间:1799607700秒 算法:类 Algorithms.FNA.FNA 运算:交集 时间:291703600 秒 算法:类 Algorithms.FNA.FNA 运算:减法 时间:1022775100 秒 算法:类 Algorithms.FNA.FNA 操作:查找 时间:1319100秒
算法:类 Algorithms.Primitive.Primitive 操作:联合 时间:81257800秒 算法:类 Algorithms.Primitive.Primitive 运算:析取 时间:85717600秒 算法:类 Algorithms.Primitive.Primitive 运算:交集 时间:0秒 算法:类 Algorithms.Primitive.Primitive 运算:减法 时间:66472900 秒 算法:类 Algorithms.Primitive.Primitive 操作:查找 时间:0秒
算法:类 Algorithms.BloomsFilter.BloomsFilter 操作:联合 时间:998900秒 算法:类 Algorithms.BloomsFilter.BloomsFilter 操作:析取 时间:0秒 算法:类 Algorithms.BloomsFilter.BloomsFilter 操作:交集 时间:503800秒 算法:类 Algorithms.BloomsFilter.BloomsFilter 操作:减法 时间:0秒 算法:类 Algorithms.BloomsFilter.BloomsFilter 操作:查找 时间:1312900秒
算法:类 Algorithms.SortedList.SortedList 操作:联合 时间:0秒 算法:类 Algorithms.SortedList.SortedList 操作:析取 时间:3721800秒 算法:类 Algorithms.SortedList.SortedList 操作:交集 时间:0秒 算法:类 Algorithms.SortedList.SortedList 操作:减法 时间:810500秒 算法:类 Algorithms.SortedList.SortedList 操作:查找 时间:1173200秒
【问题讨论】:
标签: java performance time time-complexity