Home > OS >  Why the code works on debuggin mode but not works on release mode on İntellij
Why the code works on debuggin mode but not works on release mode on İntellij

Time:03-08

I am making an experiment about algorithms efficiency, so I use different size of integer data like 512,1024,2048,..,131072,251281 when I run the code below

 for (int i=0; i<experiment.length; i  ) {
            System.out.println("experiment number : " i);

            for (int j = 0; j < 10; j  ) {

                ArrayList<Integer> exp_array = new ArrayList<>();



                if(i==9){

                    exp_array.addAll(array.subList(0, experiment[i]));
                }else {
                    exp_array.addAll(array.subList(0, experiment[i] 1));
                }

                long startTime = System.currentTimeMillis();
                insertionSort.sort(exp_array);
                long elapsedTime = System.currentTimeMillis() - startTime;
                resultsInsertion1.add(elapsedTime);


                if(j==9){
                    sortedArrays.add(exp_array);
                }

            }
            averageResultsInsertion1.add(avarage.findAverage(resultsInsertion1));
            resultsInsertion1.clear();
        }




        System.out.println(averageResultsInsertion1);


        // insertion2


        ArrayList<Long> resultsInsertion2 = new ArrayList<>();
        ArrayList<Long> averageResultsInsertion2 = new ArrayList<>();

        for (int i=0; i<experiment.length; i  ) {
            System.out.println("experiment number : " i);

            for (int j = 0; j < 10; j  ) {



                long startTime = System.currentTimeMillis();
                insertionSort.sort(sortedArrays.get(i));
                long elapsedTime = System.currentTimeMillis() - startTime;
                resultsInsertion2.add(elapsedTime);



            }
            averageResultsInsertion2.add(avarage.findAverage(resultsInsertion2));
            resultsInsertion2.clear();
        }

        System.out.println("insertion 2 : " averageResultsInsertion2);

The averaResultsInsertion2 gives me array filled with zeros but when I run the code on debugging mode it works how can I fix this problem ?

PC: MacBook Air 2017 IDE: Intellij 2022

CodePudding user response:

ResultsInsertion2 is filled with elapsed time in milliseconds, so if your sorting is executed under an millisecond you will get .. zeros

ps : please format your code next time

  • Related