What is overhead?

What is overhead? Is there a few overheads or just one? What are some examples?

+3
source share
4 answers

The business value of overhead explains this best. Material from Wikipedia:

The term service data is usually used for group expenses, which are necessary for the continued functioning of a business, but cannot be immediately associated with products / services proposed 1 (for example, not directly generate profits).

- "", , ; "" .

+4

- , , . - . . . , .

+3

:

struct first {
    char letter1;
    int number;
    char letter2;
};

struct second {
    int number;
    char letter1;
    char letter2;
};

int main ()
{
    cout << "Size of first: " << sizeof(first) << endl;
    cout << "Size of second: " << sizeof(second) << endl;
    return 0;
}

:

Size of first: 12
Size of second: 8

. char ( ) "" int down, ( ). .

: .

+3

, :

#include <stdio.h>

#define SIZE 1024

double A[SIZE][SIZE], B[SIZE][SIZE], C[SIZE][SIZE];

int main ()
{
    int i, j, k;

    for (i = 0; i < SIZE; i++) {
        for (j = 0; j < SIZE; j++) {
            for (k = 0; k < SIZE; k++) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }

    return 0;
}

:

real    0m35.137s
user    0m34.996s
sys     0m0.067s

j k:

#include <stdio.h>

#define SIZE 1024

double A[SIZE][SIZE], B[SIZE][SIZE], C[SIZE][SIZE];

int main ()
{
    int i, j, k;

    for (i = 0; i < SIZE; i++) {
        for (k = 0; k < SIZE; k++) {            // this is the only change
            for (j = 0; j < SIZE; j++) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
   }

   return 0;
}

:

real    0m5.489s
user    0m5.436s
sys     0m0.040s

This is much faster, because loop iterations are more consistent with array index strings. Thus, the data will most likely be available sequentially and therefore will be more accessible in the cache.

+1
source

Source: https://habr.com/ru/post/1770003/


All Articles