時間を実行している計算しようとしているプロセスのイムは0ナノ秒単位で実行されています。どうやって?

オマル:

イムは、私のアルゴリズムの性能を計算しようとしています。基本的に私のアルゴリズム解きは、私は解決策にプリミティブaproachを実装私のアルゴリズムが同様のアルゴリズムと比較するためにO(LOGN)でこの操作を行ってすることができ、このような交差点組合、disjuction、などの操作などを設定咲きフィルタアルゴリズム、ソートされたリストが、私はしようとしたとき、私は、他のアルゴリズムでの操作のいくつかを見て時間を実行している計算はcompliteに文字通り0(ゼロ)ナノ秒かかります。操作することにより、私は、それぞれがその中に10000要素を持っている2セットの和集合を見つけることを意味します。そんなことがあるものか?あなたは上の私のプロジェクトを参照することができGithubのを私は時間を実行している計算という部分は、テストパッケージであります

私は1つのスレッドで実行されていることを確認すべてを作るためにJprofilierを使用しようとしました

私はその計算と発見正しい結果を無視していないことを確認する時間間隔の間、デバッグしようとしました

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操作:Disjuction時間:1799607700秒アルゴリズム:クラスAlgorithms.FNA.FNA操作:交差点時間:291703600秒アルゴリズム:クラスアルゴリズム。 FNA.FNA操作:減算時間:1022775100秒アルゴリズム:クラスAlgorithms.FNA.FNA操作:検索時間:1319100秒


アルゴリズム:クラスAlgorithms.Primitive.Primitive操作:連合時刻:81257800秒アルゴリズム:クラスAlgorithms.Primitive.Primitive操作:Disjuction時間:85717600秒アルゴリズム:クラスAlgorithms.Primitive.Primitive操作:交差点時間:0秒アルゴリズム:クラスアルゴリズム。 Primitive.Primitive操作:減算時間:66472900秒アルゴリズム:クラスAlgorithms.Primitive.Primitive操作:検索時間:0秒


アルゴリズム:クラスAlgorithms.BloomsFilter.BloomsFilter操作:連合時刻:998900秒アルゴリズム:クラスAlgorithms.BloomsFilter.BloomsFilter操作:Disjuction時間:0秒アルゴリズム:クラスAlgorithms.BloomsFilter.BloomsFilter操作:交差点時間:503800秒アルゴリズム:クラスアルゴリズム。 BloomsFilter.BloomsFilter操作:減算時間:0秒アルゴリズム:クラスAlgorithms.BloomsFilter.BloomsFilter操作:検索時間:1312900秒


アルゴリズム:クラスAlgorithms.SortedList.SortedList操作:連合時間:0秒アルゴリズム:クラスAlgorithms.SortedList.SortedList操作:Disjuction時間:3721800秒アルゴリズム:クラスAlgorithms.SortedList.SortedList操作:交差点時間:0秒アルゴリズム:クラスアルゴリズム。 SortedList.SortedList操作:減算時間:810500秒アルゴリズム:クラスAlgorithms.SortedList.SortedList操作:検索時間:1173200秒


レオン:

Instant.now()ミリ秒単位で現在の時刻を使用することになります。あなたはそれを使用して見ることができるコードの中に掘りますSystem.currentTimeMillis()代わりに、上記のアプローチを使用しての私はナノ秒単位の時間を使用している次のコードを使用することができます。

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

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=119745&siteId=1