eatoncys edited a comment on issue #24238: [SPARK-27320][SQL]Converting seq to 
array in AggregationIterator to improve its access performance
URL: https://github.com/apache/spark/pull/24238#issuecomment-477837590
 
 
   @HyukjinKwon, I constructed a test case that used `for` and `index` to 
access a list which hive 1000 elements, the result is like below, 
`calculateWithFor` is 6x faster than `calculateWithIndex`
   
   calculateWithIndex cost: 6813710 ns
   calculateWithFor    cost: 1257866 ns
   
   
   ```
   def calculateWithFor(in: Seq[Int]): Array[Int] = {
       val result = new Array[Int](in.length)
       var i: Int = 0
       for (x <- in) {
         result(i) = x
         i = i + 1
       }
       result
     }
   
     def calculateWithIndex(in: Seq[Int]): Array[Int] = {
       val result = new Array[Int](in.length)
       val length = in.length
       var i: Int = 0
       while(i < length) {
         result(i) = in(i)
         i = i + 1
       }
       result
     }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to