rlwhitcomb / utilities

Some of my personal utility programs
MIT License
2 stars 0 forks source link

Optimize speed of Calc "fill" function for arrays by preallocating the space required #627

Closed rlwhitcomb closed 7 months ago

rlwhitcomb commented 10 months ago

This will require a new method in ArrayScope

rlwhitcomb commented 7 months ago

Did some testing wrt to using DynamicArray instead of ArrayList. The results were that for "small" arrays (say 100,000) DynamicArray was a little bit faster if we preallocate all the space for both beforehand. For 1,000,000 (or 10x the size) ArrayList was faster (maybe because DynamicArray is allocating up to the next power of two in size). BUT if we don't preallocate the space for ArrayList, then DynamicArray is faster. Thereby proving that preallocation using ArrayList is the best strategy for speeding this up.

rlwhitcomb commented 7 months ago

Note: I'm not sure how much time I thought this would save, nor the use case where it might make any difference at all, but the previously mentioned tests for one million values saved about 0.01 seconds to preallocate ... on a ten-year-old laptop. So, NOT very impressive. Sigh!