Performance issues with nested loops and string concatenations

前端 未结 8 723
轻奢々
轻奢々 2021-01-28 10:43

Can someone please explain why this code is taking so long to run (i.e. >24 hours): The number of rows is 5000, whilst the number of columns is 2000 (i.e. Approximately 10m loop

8条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-28 11:18

    Supposing that textToWrite is a String, you should use StringBuilder instead. String is immutable and it is very ineffective to add small parts.

    Ideally you would initialize StringBuilder with a reasonable size (see doc).

提交回复
热议问题