http://stackoverflow.com/questions/18097756/fastest-way-to-add-an-item-to-an-array
What is the fastest way to add a new item to an existing array?
Dim arr As Integer() = {1, 2, 3}
Dim newItem As Integer = 4
(I already know that when working with dynamic list of items you should rather use a List
, ArrayList
or similar IEnumerables
. But what to do if you're stuck to legacy code that uses arrays?)
What I've tried so far:
' A) converting to List, add item and convert back
Dim list As List(Of Integer)(arr)
list.Add(newItem)
arr = list.ToArray()
' --> duration for adding 100.000 items: 33270 msec
' B) redim array and add item
ReDim Preserve arr(arr.Length)
arr(arr.Length - 1) = newItem
' --> duration for adding 100.000 items: 9237 msec
' C) using Array.Resize
Array.Resize(arr, arr.Length + 1)
arr(arr.Length - 1) = newItem
' --> duration for adding 100.000 items: 1 msec
' --> duration for adding 100.000.000 items: 1168 msec
answer is C)
'Coding > VB C C++' 카테고리의 다른 글
빌드할 때 의존하는 dll 모두 복사하기 (0) | 2017.10.19 |
---|---|
vb.net 2012 setup package creation (0) | 2017.05.20 |
bcpp 5.5 사용시 자주 써먹는 유틸리티 함수들 (0) | 2016.03.22 |
use System.Numerics (0) | 2016.02.19 |
bitmap, picturebox, pixel color, image overlay, ... (0) | 2016.02.17 |