I’ve done your suggestion 1 and can see some marginal improvement, so will keep it, but in this case your 2nd suggestion is slowing things down dramatically. I’ve made it as such:
#Preallocate an array depending on datatype and of chosen size
arrayVal::Array{UInt8,1} = Vector{UInt8}(undef, size[1]*4)
#readbytes!(fd, arrayVal,sizeof(arrayVal))
read!(fd,arrayVal)
#Close the open file
close(fd)
data = reinterpret(Int32,arrayVal)
data .= ntoh.(data)
return data
And now the results are:
@benchmark k = readVtkArray("PartAll",Idp)
BenchmarkTools.Trial:
memory estimate: 477.90 MiB
allocs estimate: 28706
--------------
minimum time: 534.921 ms (0.00% GC)
median time: 556.051 ms (0.00% GC)
mean time: 719.914 ms (22.26% GC)
maximum time: 2.025 s (71.23% GC)
--------------
samples: 9
evals/sample: 1
Which is a major decrease (if I’ve done it correctly). I am trying to make a minimal working example available in my other post (How fast is binary reading capabilities in Julia compared with other languages? - #5 by Ahmed_Salih), I will try to post it as soon as possible.
Kind regards