471,357 Members | 1,092 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 software developers and data experts.

Reading bytes from stdin efficiently


I can read bytes from a FileStream with stream.ReadByte() but that does not
handle stdin. I can read from stdin with System.Console.In using
reader.Read() but it is 6x slower.

So how do I read bytes from stdin efficiently?

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
Jun 27 '08 #1
3 6728
Jon,

The comparison to reading from a file is comparing apples to oranges.
The mechanism might be the same, but you are in fact reading from two
separate sources which have different performance profiles.

I don't know if you can make it any faster, but you can try calling
GetStdHandle through the P/Invoke layer to see if you can get any better
results.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Jon Harrop" <jo*@ffconsultancy.comwrote in message
news:dL******************************@posted.plusn et...
>
I can read bytes from a FileStream with stream.ReadByte() but that does
not
handle stdin. I can read from stdin with System.Console.In using
reader.Read() but it is 6x slower.

So how do I read bytes from stdin efficiently?

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u

Jun 27 '08 #2
On Jun 4, 5:37 pm, Jon Harrop <j...@ffconsultancy.comwrote:
I can read bytes from a FileStream with stream.ReadByte() but that does not
handle stdin. I can read from stdin with System.Console.In using
reader.Read() but it is 6x slower.

So how do I read bytes from stdin efficiently?
Well, one problem is that Console.In doesn't handle bytes - it handles
*characters*. I would be somewhat wary of trying to pipe non-textual
information via Console.In. There may well be a sure-fire way of
getting it to work (and Console.OpenStandardInput would be my first
port of call) but I'd still be somewhat wary.

Is this in aid of optimising the sumcol (or sumfile, the name seems to
vary) benchmark?

Jon
Jun 27 '08 #3
Jon Skeet [C# MVP] wrote:
On Jun 4, 5:37 pm, Jon Harrop <j...@ffconsultancy.comwrote:
>I can read bytes from a FileStream with stream.ReadByte() but that does
not handle stdin. I can read from stdin with System.Console.In using
reader.Read() but it is 6x slower.

So how do I read bytes from stdin efficiently?

Console.OpenStandardInput would be my first port of call...
That is exactly the answer I was looking for, thank you.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Xah Lee | last post: by
6 posts views Thread by Charlie Zender | last post: by
3 posts views Thread by James Dean | last post: by
1 post views Thread by Keith Kingsley | last post: by
111 posts views Thread by Tonio Cartonio | last post: by
7 posts views Thread by Markus Mayer | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.