- There is a std :: vector, in each of them there are still vectors, in each of them there are also vectors.
- Case 0: In the most recent nested vector, there are numbers 1 byte in size, with options of values: 0,1,2.
vector<unsigned char> v;The comparison itself:if (char0 == char1) Case 1: In the most recent nested vector are pointers to numbers 1 byte in size. Variants of values: 0,1,2., But only pointers to them are stored in vector. The comparison itself:
if (ptr_char0 == ptr_char1)int i0 = 0; int i1 = 1; int i2 = 2;
vector<unsigned char*> v;Case 2: similar to case 1, but will be taken to compare the values on the pointers. The comparison itself:
if (*ptr_char0 == *ptr_char1)- The lengths of each "level" vector are different and change over time. It is necessary to go through all the elements and make a comparison (only for equality). Delete something, change something, add elements or vector somewhere, but the action pattern (if-else) is the same for both cases.
Will it be faster to compare variables or pointers, or take values for comparison by pointers, or some other variant?
The following example showed that the fastest case is # 2, which, on the contrary, should be the slowest way.
int n0=10; int n1=20; int *p0 = &n0; int *p1 = &n1; int *q0 = &n0; int *q1 = &n1; int time0 = clock(); for (int i=0;i!=25500000;++i) if (n0==n1){} int time1 = clock(); for (int i=0;i!=25500000;++i) if (p0==p1){} int time2 = clock(); for (int i=0;i!=25500000;++i) if (*q0==*q1){} int time3 = clock(); printf("%i %i %i %i",time0,time1,time2,time3); Exhaust: 311 312 313 313
Obviously, the load is too small in this example, it is difficult to estimate.
int a = 123, b = 123; int *p = &a, *q = &b;int a = 123, b = 123; int *p = &a, *q = &b;. What do you want to get in this case when comparingpandqand how are you going to get by with "comparing pointers"? - AnT