Populating swift two dimensional array using append vs element by element

Using Apple Swift: I have a very large 2D String array from, for example, a .cdl file. Then I create a Double array from a String array, so now I have a String array (variableData) and a double array (variableDataDouble). Now I want to customize the values ​​in the Double array.

If I use append and a String array, the setup is fast.

cdlVariablesDictionary[eachVariable]?.variableDataDouble.removeAll()
for rows in 0 ..< rowsCount {
     var tempArray: [Double] = []
     for columns in 0 ..< columnsCount {
         var adjustedValue: Double =  Double((cdlVariablesDictionary[eachVariable]?.variableData[rows][columns])!)!
         adjustedValue = adjustedValue * scaleNumeric + offsetNumeric
         tempArray.append(adjustedValue)
     }
     cdlVariablesDictionary[eachVariable]?.variableDataDouble.append(tempArray)
}

      

If I adjust each value in the Double array, the adjustment is very slow.

for rows in 0 ..< rowsCount {
     for columns in 0 ..< columnsCount {
          var adjustedValue: Double = (cdlVariablesDictionary[eachVariable]?.variableDataDouble[rows][columns])!
          adjustedValue = adjustedValue * scaleNumeric + offsetNumeric
          cdlVariablesDictionary[eachVariable]?.variableDataDouble[rows][columns] = adjustedValue
     }
}

      

Why is append fast and element-to-element very, very slow?

+3
arrays append swift


source to share


No one has answered this question yet

Check out similar questions:

7494
How can I remove a specific element from an array in JavaScript?
2895
How do I add something to the array?
2335
Removing an element from an array in PHP
1364
How do I add new array elements at the beginning of an array in Javascript?
1297
Removing array elements in JavaScript - removing vs-splice
1250
How can I concatenate two arrays in Java?
1071
How do I create a two dimensional array in JavaScript?
995
How do I sort a multidimensional array by value?
870
Swift Beta: Sorting Arrays
703
Swift for loop: for index, item in array?



All Articles
Loading...
X
Show
Funny
Dev
Pics