Julia slower than Python for finding pangrams?

We can shave this one a bit with a mask:

julia> mask = UInt32(2^26 - 1)
0x03ffffff

julia> function ispangram6(input::String)
                  a,A,z,Z = UInt8('a'),UInt8('A'),UInt8('z'),UInt8('Z')
                  appears::UInt32 = 0
                  @inbounds for b in codeunits(input)
                      if A ≤ b ≤ Z
                          appears |= one(UInt32) << (b-A)
                      elseif a ≤ b ≤ z
                          appears |= one(UInt32) << (b-a)
                      end
                      iszero(appears ⊻ mask) && return true
                  end
                  false
              end
ispangram6 (generic function with 1 method)

julia> @btime ispangram5($input)
  82.210 ns (0 allocations: 0 bytes)
true

julia> @btime ispangram6($input)
  3.135 μs (91 allocations: 1.42 KiB)
true

julia> ispangram6("abcdeghijklmnopqrstuvwxyz")
false
1 Like