Source code attached:

```
# This file is intended to be part of Julia. License is MIT: https://julialang.org/license
using BenchmarkTools
using Base.Test
to_hexstring(arr::Array{UInt8,1}) = join([hex(i, 2) for i in arr])
# This is the default benchmark for the calculation
from_hexstringS1(s::AbstractString) = hex2bytes(s)
# This uses the same logic as hex2bytes
function from_hexstringB1(s::Vector{UInt8})
const DIGIT_ZERO = UInt('0')
const DIGIT_NINE = UInt('9')
const LATIN_UPPER_A = UInt('A')
const LATIN_UPPER_F = UInt('F')
const LATIN_A = UInt('a')
const LATIN_F = UInt('f')
len = length(s)
if isodd(len)
error("Input string length should be even")
end
arr = zeros(UInt8, div(len,2))
i = j = 1
# This line is important as this ensures computation happens in word boundary and not
# byte boundary. Byte boundary computation can be almost 10 times slower.
n = c = UInt(0)
while i < len
n = 0
c = s[i]
n = DIGIT_ZERO <= c <= DIGIT_NINE ? c - DIGIT_ZERO :
LATIN_A <= c <= LATIN_F ? c - LATIN_A + 10 :
LATIN_UPPER_A <= c <= LATIN_UPPER_F ? c - LATIN_UPPER_A + 10 : error("Input string isn't a hexadecimal string")
i += 1
c = s[i]
n = DIGIT_ZERO <= c <= DIGIT_NINE ? n << 4 + c - DIGIT_ZERO :
LATIN_A <= c <= LATIN_F ? n << 4 + c - LATIN_A + 10 :
LATIN_UPPER_A <= c <= LATIN_UPPER_F ? n << 4 + c - LATIN_UPPER_A + 10 : error("Input string isn't a hexadecimal string")
i += 1
arr[j] = n
j += 1
end
return arr
end
function from_hexstringB2(s::Vector{UInt8})
const DIGIT_ZERO = UInt8('0')
const DIGIT_NINE = UInt8('9')
const LATIN_UPPER_A = UInt8('A')
const LATIN_UPPER_F = UInt8('F')
const LATIN_A = UInt8('a')
const LATIN_F = UInt8('f')
len = length(s)
if isodd(len)
error("Input string length should be even")
end
arr = zeros(UInt8, div(len,2))
i = j = 1
# This line is important as this ensures computation happens in word boundary and not
# byte boundary. Boundary computation can be almost 10 times slower
# n = c = UInt(0)
while i < len
n = 0
c = s[i]
n = DIGIT_ZERO <= c <= DIGIT_NINE ? c - DIGIT_ZERO :
LATIN_A <= c <= LATIN_F ? c - LATIN_A + 10 :
LATIN_UPPER_A <= c <= LATIN_UPPER_F ? c - LATIN_UPPER_A + 10 : error("Input string isn't a hexadecimal string")
i += 1
c = s[i]
n = DIGIT_ZERO <= c <= DIGIT_NINE ? n << 4 + c - DIGIT_ZERO :
LATIN_A <= c <= LATIN_F ? n << 4 + c - LATIN_A + 10 :
LATIN_UPPER_A <= c <= LATIN_UPPER_F ? n << 4 + c - LATIN_UPPER_A + 10 : error("Input string isn't a hexadecimal string")
i += 1
arr[j] = n
j += 1
end
return arr
end
const mb_10 = (10 << 20)
arr=UInt8[rand(['0','1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f'])
for x = 1:mb_10]
str = String(arr)
b_str = from_hexstringS1(str)
f_hsB1() = from_hexstringB1(arr)
f_hsB2() = from_hexstringB2(arr)
f_hsS1() = from_hexstringS1(str)
@test str == to_hexstring(from_hexstringB1(arr))
@test str == to_hexstring(from_hexstringB2(arr))
@test str == to_hexstring(from_hexstringS1(str))
# Executing to make sure the code gets JIT compiled
f_hsB1()
f_hsB2()
f_hsS1()
```