# Underperformant mapreduce

**URL:** https://discourse.julialang.org/t/underperformant-mapreduce/83624
**Category:** Performance
**Created:** [July 1, 2022, 2:10pm UTC](https://discourse.julialang.org/t/underperformant-mapreduce/83624 "2022-07-01T14:10:29Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)
#### Post date: [July 1, 2022, 2:10pm UTC](https://discourse.julialang.org/t/underperformant-mapreduce/83624/1 "2022-07-01T14:10:29Z")

</div>

Conceptually, shouldn’t the `mapreduce` version be faster than the `reduce` version?

Granted, the difference is not much, but there are consistently some nanoseconds missing.

```julia
julia> N = 5115;

julia> a1 = rand(Bool, N);

julia> a2 = rand(Bool, N);

julia> b1 = BitArray(a1);

julia> b2 = BitArray(a2);

julia> @btime reduce(xor, xor.($b1, $b2))
  2.644 μs (2 allocations: 768 bytes)
true

julia> @btime mapreduce(xor, xor, $b1, $b2)
  2.656 μs (2 allocations: 768 bytes)
true

```

## Bonus

Can anyone tell me why the Vector{Bool} version is:

- For `mapreduce`, faster than any other
- For `reduce`, slower than any other

```julia-auto
julia> @btime mapreduce(xor, xor, $a1, $a2)
  1.922 μs (4 allocations: 5.22 KiB)
true

julia> @btime reduce(xor, xor.($a1, $a2))
  3.587 μs (3 allocations: 4.94 KiB)
true

```
