# Type piracy?

**URL:** <https://discourse.julialang.org/t/type-piracy/9713>\
**Category:** General Usage\
**Tags:** type-piracy\
**Created:** [March 14, 2018, 11:45am UTC](https://discourse.julialang.org/t/type-piracy/9713 "2018-03-14T11:45:33Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [March 14, 2018, 1:40pm UTC](https://discourse.julialang.org/t/type-piracy/9713/7 "2018-03-14T13:40:43Z")

</div>

I was just toying around with this and found the following weird performance issue (Julia Version 0.7.0-DEV.4570):

```julia
function f(::Type{UInt16}, x::NTuple{2, UInt8})
    x1 = 0x0001 * x[1]
    x2 = 0x0100 * x[2]
    x1 + x2
end

const NBytes{N} = NTuple{N, UInt8}
function f(::Type{UInt16}, x::NBytes{2})
    x1 = 0x0001 * x[1]
    x2 = 0x0100 * x[2]
    x1 + x2
end

julia> @btime f(UInt16, (0x01, 0x02))
  0.017 ns (0 allocations: 0 bytes)
0x0201

julia> x = NBytes((0x01, 0x02))
(0x01, 0x02)

julia> @btime f(UInt16, $x)
  1.690 ns (0 allocations: 0 bytes)
0x0201

```

---

_[View the full topic](https://discourse.julialang.org/t/type-piracy/9713)._
