Here's an example of how to put the good advice in this thread into practice: if you go for performance, use the `zero_functional` package instead of `std/sequtils` for functional code and take a look at what the good people at Status.im have for the rest. With that, the CSV reader code looks like this: import std/strutils import faststreams/[inputs, textio] import zero_functional const numRows = 10000000 iterator numbers(inp: InputStream): uint = while inp.readable: yield inp.readUnsignedInt discard inp.read proc main() = echo "Expected total = ", 3*numRows * (3*numRows - 1) div 2 echo "Actual total = ", fileInput("./nim.csv").numbers --> sum() main() Run
I modified the code creating the `.csv` file to produce 10 million rows of data to make benchmarking easy. Compilation options were `-d:release` for Nim and `-O` for Rust. The resulting Nim program has less than a twentieth of the size of the Rust reader (!) and is approximately 30% faster on my machine. Also, the Rust code looks like ASCII art with special characters in comparison IMHO. The downsides of this approach: Status' packages - like `faststreams` \- can be tricky to get working and the Nim code becomes dramatically slower with `--mm:orc` which will be the default soon. The latter could be due to me not knowing the right tricks/annotations though.