Is there a way to speed up this code?

There are ways to do this faster: Package to read/process lines without new allocations

But for this specific task of reading a sequence of lines containing space-delimited numbers that you want to parse, I would look at CSV.Rows in CSV.jl, or simply CSV.File with a limit=num_atoms argument.

1 Like