Ad
  • Default User Avatar

    If it were only the sum() or only the fold() as on stackoverflow this would be true.
    But benchmarking shows that combining map() and sum() is about 10% slower.
    Also, using iter() instead of into_iter() will degrade performance by another 30-40%.

    Using vectors with 100 million elements on my machine:
    iter + map + sum = ~3.1-3.3s
    into_iter +map + sum = ~2.5-2.6s
    iter + fold = ~2.9-3.1s
    into_iter + fold = ~2.3-2.4s

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution