# Fast reading of multiple big-endian binary files

**URL:** <https://discourse.julialang.org/t/fast-reading-of-multiple-big-endian-binary-files/52060>\
**Category:** Performance\
**Tags:** binaryio\
**Created:** [December 18, 2020, 5:02pm UTC](https://discourse.julialang.org/t/fast-reading-of-multiple-big-endian-binary-files/52060 "2020-12-18T17:02:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Lei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thomas_lei/32/20372_2.png) [@Thomas\_Lei](https://discourse.julialang.org/u/Thomas_Lei)\
**Post date:** [December 18, 2020, 5:02pm UTC](https://discourse.julialang.org/t/fast-reading-of-multiple-big-endian-binary-files/52060/1 "2020-12-18T17:02:37Z")

</div>

Hi all,

I have to read and preprocess a huge quantity of binary (big-endian) data from thousands of files. I managed to get everything to work properly, but my function is slow… However, as I’m a Julia beginner, I doubt my coding is optimal.

Here is the code snippet :

```julia
    function readBinaryFile(file::AbstractString)

        @info string("Reading binary file ", file)
        nInt32 = (numberOfChannels + headerSize)*samplesPerFile
        temp = Vector{Int32}(undef, nInt32)

        open(file) do io
            read!(io, temp)
        end

        temp .= ntoh.(temp)
        temp = reshape(temp, (numberOfChannels+headerSize, samplesPerFile))
        data = convert(Array{Float64,2}, temp[headerSize+1:end,:])/2^12

        return transpose(data)

    end

```

Any way of doing it faster ?

Cheers,  
Thomas

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 18, 2020, 5:13pm UTC](https://discourse.julialang.org/t/fast-reading-of-multiple-big-endian-binary-files/52060/2 "2020-12-18T17:13:47Z")

</div>

What happens to the speed if you use `data = convert(Array{Float64,2}, @view temp[headerSize+1:end,:])*2^-12`? That will save a copy, which should help a lot.
