Efficiency of sorting algorithms test

Earlier we wrote several common sorting algorithm, and analyzed the situation of various algorithms to realize the complexity of thought and time, but because of parses and wood to do the actual data comparison test, the efficiency of each algorithm did not a clear concept, let's take a look at the efficiency gap between the same algorithm through specific tests.

11 Statement length element 100 ranges from 0 to 1000 of the sequence

int length = 100;
int[] testArray1 = new int[length];
int[] testArray2 = new int[length];
int[] testArray3 = new int[length];
int[] testArray4 = new int[length];
int[] testArray5 = new int[length];
int[] testArray6 = new int[length];
int[] testArray7 = new int[length];
int[] testArray8 = new int[length];
int[] testArray9 = new int[length];
int[] testArray10 = new int[length];
int[] testArray11 = new int[length];
Random random = new Random();

for (int i = 0; i < length; i++)
{
    int temp = random.Next(0,1000);
    testArray1[i] = temp;
    testArray2[i] = temp;
    testArray3[i] = temp;
    testArray4[i] = temp;
    testArray5[i] = temp;
    testArray6[i] = temp;
    testArray7[i] = temp;
    testArray8[i] = temp;
    testArray9[i] = temp;
    testArray10[i] = temp;
    testArray11[i] = temp;
}

Run the test, the test results screenshot:

1

At first glance, the efficiency of wood between several algorithms like there are differences, some time ago we set the high complexity of the algorithm even faster. Do not worry, let us increase the number of elements in the sequence to try again, the length = 100 was changed to length = 1000 run the test again and the results screenshot:

2

The results can already be seen, low time complexity of the algorithm is leading, but the effect does not seem obvious. Let's change the length = 1000 run length = 10000 test results shots again:

3

The test result has been a qualitative change, I believe that through the test we have a clear idea of ​​efficiency between different time complexity of the algorithm.

Reproduced in: https: //my.oschina.net/secyaher/blog/274437

Guess you like

Origin blog.csdn.net/weixin_33928467/article/details/91966958