  Rank: Advanced Member Groups: Registered
Joined: 17/01/2013(UTC) Posts: 296   Location: Khabarovsk, Russia Was thanked: 151 time(s) in 107 post(s)
|
Originally Posted by: Razonar  I understand that stack or augment are bad strategies, but without pre-allocation is better than with pre-allocation? If it is, why is without pre that good. Seems to be to much faster than I can explain or understand. Much faster than what? Please provide an example to discuss. Originally Posted by: Razonar  Preallocating is when you say "let's V:=matrix(20,1)", and then just work defining V[1, V[2 ... etc. If you found that don't need all 20 numbers, just can use submatrix. But if you don't preallocate V, but use V[1 ... V[20, and program work fast, who is preallocating must to be SMath, and that's isn't very efficient for the general cases. Or have some pointer very good for handle that matrices, and I don't know C at that level. It's a common practice in libraries to pre-allocate some space for any container. Without this, it would be very inefficient to manage memory. Further, re-allocation strategies on the low level are quite efficient, because they either use % of current size to grow (typical are 2x or golden ratio), or linked lists that don't need reallocation at all. SMath doesn't need to do that itself, because it's .NET that does that for it. And it's VERY efficient for general cases. Originally Posted by: Razonar  It is supossed that second algorithm must to be faster than your's, but it isn't. Well, your slower second time could be explained like this: pre-allocation in SMath is high-level operation, and it simply adds one additional high-level (slow) operation. And it could explain something, if not one little thing ... actually it doesn't matter.  SMath calculation time is very volatile, and it's hard to measure time reliably, even doing multiple comparisons/calculations. E.g., processor temperature, that raises towards second calculation, may cause it to slow down to prevent overheating (contemporary systems do that). Some memory leaks in SMath may cause slow-down of all subsequent calculations (and when the sheet is done calculation, .NET garbage collection may clean it up, so recalculation shows the same picture). Here is a screenshot that shows that your "second" calculation, put first, outperforms original.  |
Best regards, Mike Kaganski |