Find both min and max together: algorithm should be faster but isn't
问题 I'm trying to implement an algorithm to find the minimum and the maximum values among a set of longs in a file. My test file contains one billion longs. The algorithm works as expected but does not perform faster than the naive version. It should be significantly faster as the naive version performs roughly 2n comparisons, whereas this version performs 3n/2 comparisons. $ time ./findminmax_naive somelongs count: 1000000000 min: 0 max: 2147483647 real 0m24.156s user 0m4.956s sys 0m3.896s $