Process im trying to calculate running time is executing in 0 nanoseconds. how?

Ömer :

Im trying to calculate my algorithm performance. Basically my algorithm solves set operations such as union, disjuction, intersection etc. My algorithm can done this operations in O(logn) to compare with similar algorithms i implement a primitive aproach to solution, blooms filter algorithm, Sorted List but when i tried to calculate running time i saw some of the operations in other algorithm takes literally 0(zero) nanosecond to complite. By the operation i mean finding union of two set each has 10000 element in it. How is that possible? you can see my project on Github. Part that i calculate running time is at the test package

I've tried to use Jprofilier to make sure it all running on one thread

I've tried to debug between to time intervals to make sure its not neglecting calculation and finds correct results

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
}

This is how i print result

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("------------------------------------------------------------------------------");

Result looks like this


Algorithm: class Algorithms.FNA.FNA Operation: Union Time: 1851133600 seconds Algorithm: class Algorithms.FNA.FNA Operation: Disjuction Time: 1799607700 seconds Algorithm: class Algorithms.FNA.FNA Operation: Intersection Time: 291703600 seconds Algorithm: class Algorithms.FNA.FNA Operation: Subtraction Time: 1022775100 seconds Algorithm: class Algorithms.FNA.FNA Operation: Find Time: 1319100 seconds


Algorithm: class Algorithms.Primitive.Primitive Operation: Union Time: 81257800 seconds Algorithm: class Algorithms.Primitive.Primitive Operation: Disjuction Time: 85717600 seconds Algorithm: class Algorithms.Primitive.Primitive Operation: Intersection Time: 0 seconds Algorithm: class Algorithms.Primitive.Primitive Operation: Subtraction Time: 66472900 seconds Algorithm: class Algorithms.Primitive.Primitive Operation: Find Time: 0 seconds


Algorithm: class Algorithms.BloomsFilter.BloomsFilter Operation: Union Time: 998900 seconds Algorithm: class Algorithms.BloomsFilter.BloomsFilter Operation: Disjuction Time: 0 seconds Algorithm: class Algorithms.BloomsFilter.BloomsFilter Operation: Intersection Time: 503800 seconds Algorithm: class Algorithms.BloomsFilter.BloomsFilter Operation: Subtraction Time: 0 seconds Algorithm: class Algorithms.BloomsFilter.BloomsFilter Operation: Find Time: 1312900 seconds


Algorithm: class Algorithms.SortedList.SortedList Operation: Union Time: 0 seconds Algorithm: class Algorithms.SortedList.SortedList Operation: Disjuction Time: 3721800 seconds Algorithm: class Algorithms.SortedList.SortedList Operation: Intersection Time: 0 seconds Algorithm: class Algorithms.SortedList.SortedList Operation: Subtraction Time: 810500 seconds Algorithm: class Algorithms.SortedList.SortedList Operation: Find Time: 1173200 seconds


LeoN :

Instant.now() will be using the current time in milliseconds. Digging in to the code you can see it uses System.currentTimeMillis(). Instead of using the above approach you can use the following code where I have used the time in nano seconds.

static long IntersectDocumentsTime(AlgorithmInterface algorithm) {
    long start = System.nanoTime();
    algorithm.IntersectDocuments();
    long end = System.nanoTime();
    long durationInNanos = end - start;
    return durationInNanos;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=116342&siteId=1