I find the performance on this to be terrible.
Can you define 'terrible performance'? Given that the array you use has only a size of four elements (or three, if you don't zero-based `ii`), I wonder how such a small array can cause so bad performance.
* * *
The performance of a dynamic array is around twice as slow as a fixed size array. With an array of 10,000 elements:
Code: Select all
Fixed size array took 7.2620 seconds.
Dynamic array took 14.5950 seconds.
Fixed size array took 7.2330 seconds.
Dynamic array took 14.5000 seconds.
Fixed size array took 7.2850 seconds.
Dynamic array took 14.5760 seconds.
Test code*:
Code: Select all
Variables:
oneSecondDT(ELTimeToDateTime_s(1)),
startTime(0), endTime(0), runTime(0),
arrayCount(10000), x(0), y(0);
Arrays:
fixedSize[10000](0),
dynamicArray[](0);
once (LastBarOnChart_s = true) begin
// Fixed array
for y = 0 to 50 begin
startTime = ComputerDateTime;
for x = 0 to arrayCount begin
fixedSize[x] = Random(10);
end;
for x = 0 to arrayCount begin
value1 = Array_Sum(fixedSize, 0, arrayCount);
end;
endTime = ComputerDateTime;
runTime = runTime + (endTime - startTime);
end;
Print("Fixed size array took ", NumToStr(runTime / oneSecondDT, 4), " seconds.");
// Dynamic array
for y = 0 to 50 begin
startTime = ComputerDateTime;
Array_SetMaxIndex(dynamicArray, arrayCount);
for x = 0 to arrayCount begin
dynamicArray[x] = Random(10);
end;
for x = 0 to arrayCount begin
value1 = Array_Sum(dynamicArray, 0, arrayCount);
end;
endTime = ComputerDateTime;
runTime = runTime + (endTime - startTime);
end;
Print("Dynamic array took ", NumToStr(runTime / oneSecondDT, 4), " seconds.");
end;
*: Don't click the MultiCharts program during this test. Apparently MultiCharts64 Version 8.8 Release (Build 8967) is not stable enough to do that without hanging.
But on-topic: if 10,000 array elements being summed give an execution time of 14,5 seconds, I doubt a little bit how your 3 elements array can give a terrible performance. Can perhaps something else in your code explain the poor performance?
Extrapolating from this small test, a 3 elements array should (in theory
) take 0.00145 seconds for both populating and calling the `Array_Sum()` keyword.