Why is Rust Stream Reading Slower than Node.js?

0
7
Asked By CuriousCoder42 On

I'm trying to understand why reading streams in Rust seems to take significantly more time compared to Node.js. I executed both programs with the following results: Rust took about 9 milliseconds while Node.js only took roughly 0.21 milliseconds. I've set up a server in both languages, and I'm running them with optimized commands. I'd love to hear about what I might be missing in my Rust code that could explain this performance gap!

2 Answers

Answered By DevGuru88 On

You made a good point about the measurement method! In your Node.js code, it appears you're actually only measuring the write time to the socket, while the Rust code encompasses reading, writing, and printing. This discrepancy means the comparison isn't entirely valid. Perhaps try to isolate just the reading part in both setups to get a clearer picture of performance.

Answered By TechWhiz99 On

It looks like your issue might arise from how you're timing the operations. In your Rust code, you’re measuring not only the read time but also the time spent on printing to the console, which can be pretty slow. This could inflate the timings you're seeing and not give you an accurate representation of how fast Rust can read streams. Try removing the print statements during your read to see if that changes your timings.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.