HaoYang670 commented on issue #1400:
URL: https://github.com/apache/arrow-rs/issues/1400#issuecomment-1059882916


   Strongly agree with you @jhorstmann. `fold` seems to copy all elements in 
the array, and `reduce` just takes the references. If the code is rewritten as
   ```rust
       if null_count == 0 {
           // optimized path for arrays without null values
           m.iter()
               .copied()
               .reduce(|acc, item| if cmp(&acc, &item) { item } else { acc })
   ```
   and I can get the benchmark result:
   ```console
   min 512                 time:   [833.73 ns 834.34 ns 835.06 ns]              
       
                           change: [-0.2047% -0.0757% +0.0383%] (p = 0.24 > 
0.05)
                           No change in performance detected.
   Found 5 outliers among 100 measurements (5.00%)
     4 (4.00%) high mild
     1 (1.00%) high severe
   ```
   , which is same as `fold`.
   
   But wait! Which one is faster in this context, copy or reference? On my 
desktop, I can get 50% performance improvement by using reference. However, you 
said `fold` was faster on your laptop. Is it a little weird?


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to