# Is there a way to speed up this code?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-speed-up-this-code/102878>\
**Category:** Performance\
**Tags:** question, parsing, io\
**Created:** [August 16, 2023, 7:11pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-speed-up-this-code/102878 "2023-08-16T19:11:43Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 16, 2023, 9:26pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-speed-up-this-code/102878/4 "2023-08-16T21:26:44Z")

</div>

> [@Jeff\_Emanuel](#):
>
> Consider reading the file all at once instead of line-by-line.

There are ways to do this faster: [Package to read/process lines without new allocations](https://discourse.julialang.org/t/package-to-read-process-lines-without-new-allocations/92448)

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](https://csv.juliadata.org/stable/reading.html#CSV.Rows), or simply [`CSV.File`](https://csv.juliadata.org/stable/reading.html#CSV.File) with a `limit=num_atoms` argument.

---

_[View the full topic](https://discourse.julialang.org/t/is-there-a-way-to-speed-up-this-code/102878)._
