source/benchmark.c
int benchmark(int algorithm)
{
    //Algorithm types:
    /*
    1 - Bubble Sort
    2 - Selection Sort
    3 - Insertion Sort
    4 - Shell Sort
    5 - Heap Sort
    6 - Merge Sort
    7 - Quick Sort
    8 - Counting Sort
    */

    clock_t start_time, end_time;
    double cpu_time_used, memory_used;
    /*size_t peakSize;*/
    int error;

    int vector_size = 2000, generation_type = 1; //Standard benchmark, vector with 2000 integers and ascending number generation.
    //Generation types:
    /*
    1 - Ascending.
    2 - Descending.
    3 - Random.
    */

    //Runs benchmark until vector size reaches 128000 integers.
    do
    {

        //Runs benchmark for every type of vector generation (ascending, descending, random).
        do
        {

            //Vector Generation (not included in benchmark time/memory usage).
            int* vector = (int*)malloc(vector_size * sizeof(int));
            error = vectorGenerator(vector, vector_size, generation_type);
            if(error == 0)
            {
                printf("Error!\n");
                exit(1); //Means that the function "vectorGeneration" has failed to to fill the vector with integers.
            }


            //Benchmark start.
            start_time = clock();

            switch(algorithm)
            {
                case 1:
                    bubbleSort(vector, vector_size);
                    break;

                case 2:
                    selectionSort(vector, vector_size);
                    break;

                case 3:
                    insertionSort(vector, vector_size);
                    break;

                case 4:
                    shellSort(vector, vector_size);
                    break;

                case 5:
                    heapSort(vector, vector_size);
                    break;

                case 6:
                    mergeSort(vector, vector_size);
                    break;

                case 7:
                    quickSort(vector, vector_size);
                    break;

                case 8:
                    countingSort(vector, vector_size);
                    break;

                default:
                    exit(300); //Means that the algorithm is invalid.
            }


            //Benchmark end.
            end_time = clock();
            cpu_time_used = ((double) (end_time - start_time)) / CLOCKS_PER_SEC;
            memory_used = get_memory_used_MB();


            //Checks if vector if sorted:
            error = vectorVerifier(vector, vector_size);
            if(error == 0)
            {
                printf("Invalid Benchmark!\n");

                exit(100); //Means that the benchmark is invalid because the vector is not sorted properly!
            }
            free(vector);


            //Shows status on console:
            printResults(cpu_time_used, memory_used, algorithm, vector_size, generation_type);


            //Saves results in text file:
            saveResults(cpu_time_used, memory_used, algorithm, vector_size, generation_type);

            generation_type++;
        } while(generation_type <= 3);

        vector_size *= 2;
        generation_type = 1;
    } while(vector_size <= 128000);

    return 1;
}
//Benchmark function monitors CPU runtime and memory usage of sorting algorithms.
//Receives a integer that indicates which sorting algorithm it should run.
//Returns 1 if benchmark was successful.

Benchmark function monitors CPU runtime and memory usage of sorting algorithms.
Receives a integer that indicates which sorting algorithm it should run.
Returns 1 if benchmark was successful.
Benchmark function monitors CPU runtime and memory usage of sorting algorithms . Receives a integer that indicates which sorting algorithm it should run . Returns 1 if benchmark was successful .
int benchmark(int algorithm)
{
    clock_t start_time, end_time;
    double cpu_time_used, memory_used;
    int error;
    int vector_size = 2000, generation_type = 1; 
    do
    {
        do
        {
            int* vector = (int*)malloc(vector_size * sizeof(int));
            error = vectorGenerator(vector, vector_size, generation_type);
            if(error == 0)
            {
                printf("Error!\n");
                exit(1); 
            }
            start_time = clock();
            switch(algorithm)
            {
                case 1:
                    bubbleSort(vector, vector_size);
                    break;
                case 2:
                    selectionSort(vector, vector_size);
                    break;
                case 3:
                    insertionSort(vector, vector_size);
                    break;
                case 4:
                    shellSort(vector, vector_size);
                    break;
                case 5:
                    heapSort(vector, vector_size);
                    break;
                case 6:
                    mergeSort(vector, vector_size);
                    break;
                case 7:
                    quickSort(vector, vector_size);
                    break;
                case 8:
                    countingSort(vector, vector_size);
                    break;
                default:
                    exit(300); 
            }
            end_time = clock();
            cpu_time_used = ((double) (end_time - start_time)) / CLOCKS_PER_SEC;
            memory_used = get_memory_used_MB();
            error = vectorVerifier(vector, vector_size);
            if(error == 0)
            {
                printf("Invalid Benchmark!\n");
                exit(100); 
            }
            free(vector);
            printResults(cpu_time_used, memory_used, algorithm, vector_size, generation_type);
            saveResults(cpu_time_used, memory_used, algorithm, vector_size, generation_type);
            generation_type++;
        } while(generation_type <= 3);
        vector_size *= 2;
        generation_type = 1;
    } while(vector_size <= 128000);
    return 1;
}
int benchmark ( int algorithm ) { clock_t start_time , end_time ; double cpu_time_used , memory_used ; int error ; int vector_size = 2000 , generation_type = 1 ; do { do { int * vector = ( int * ) malloc ( vector_size * sizeof ( int ) ) ; error = vectorGenerator ( vector , vector_size , generation_type ) ; if ( error == 0 ) { printf ( " \n " ) ; exit ( 1 ) ; } start_time = clock ( ) ; switch ( algorithm ) { case 1 : bubbleSort ( vector , vector_size ) ; break ; case 2 : selectionSort ( vector , vector_size ) ; break ; case 3 : insertionSort ( vector , vector_size ) ; break ; case 4 : shellSort ( vector , vector_size ) ; break ; case 5 : heapSort ( vector , vector_size ) ; break ; case 6 : mergeSort ( vector , vector_size ) ; break ; case 7 : quickSort ( vector , vector_size ) ; break ; case 8 : countingSort ( vector , vector_size ) ; break ; default : exit ( 300 ) ; } end_time = clock ( ) ; cpu_time_used = ( ( double ) ( end_time - start_time ) ) / CLOCKS_PER_SEC ; memory_used = get_memory_used_MB ( ) ; error = vectorVerifier ( vector , vector_size ) ; if ( error == 0 ) { printf ( " \n " ) ; exit ( 100 ) ; } free ( vector ) ; printResults ( cpu_time_used , memory_used , algorithm , vector_size , generation_type ) ; saveResults ( cpu_time_used , memory_used , algorithm , vector_size , generation_type ) ; generation_type ++ ; } while ( generation_type <= 3 ) ; vector_size *= 2 ; generation_type = 1 ; } while ( vector_size <= 128000 ) ; return 1 ; }
Benchmark function monitors CPU runtime and memory usage of sorting algorithms.
Benchmark function monitors CPU runtime and memory usage of sorting algorithms .
//Algorithm types:
 /*
    1 - Bubble Sort
    2 - Selection Sort
    3 - Insertion Sort
    4 - Shell Sort
    5 - Heap Sort
    6 - Merge Sort
    7 - Quick Sort
    8 - Counting Sort
    */ /*size_t peakSize;*/ //Standard benchmark, vector with 2000 integers and ascending number generation.
 //Generation types:
 /*
    1 - Ascending.
    2 - Descending.
    3 - Random.
    */ //Runs benchmark until vector size reaches 128000 integers.
 //Runs benchmark for every type of vector generation (ascending, descending, random).
 //Vector Generation (not included in benchmark time/memory usage).
 //Means that the function "vectorGeneration" has failed to to fill the vector with integers.
 //Benchmark start.
 //Means that the algorithm is invalid.
 //Benchmark end.
 //Checks if vector if sorted:
 //Means that the benchmark is invalid because the vector is not sorted properly!
 //Shows status on console:
 //Saves results in text file:
