VBA Bubble Sort Algorithm Slow

前端 未结 3 1159
执笔经年
执笔经年 2020-12-18 17:50

I am surprised at how slow this bubble sort algorithm is using VBA. So my question is am I doing something wrong/inefficient, or is this just the best VBA and bubble sort wi

3条回答
  •  伪装坚强ぢ
    2020-12-18 18:36

    My thoughts:

    • You really don't want to use an N^2 algorithm for anything that has more than 20-30 items (maximum). If you have 5000-10000 rows, starting with BubbleSort was a mistake, IMHO
    • VBA is unpredictable. Beyond ditching bubbleSort (just ask Barack Obama), you want to try different ways of doing things in VBA.

    For example:

    • Replace for ... next loops with for ... each loops: the latter (paradoxically) can be faster
    • Try using variants versus immediately converting to primitive types and using those. It used to be the case that VBA handled Variants much faster, but YMMV.

提交回复
热议问题