473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 6971
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php...
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
6
by: Charlie Zender | last post by:
Hi, I have a program which takes the output filename argument from stdin. Once the program knows the output filename, it tries to open it. If the output file exists, the program asks the user to...
7
by: eriwik | last post by:
Hi, I'm working on a small application which processes PNG-images and need to read parts of them into structures and/or variables and I was wondering what assumptions one can make about how the...
3
by: James Dean | last post by:
I create a new filestream and then i move i use the readbyte function and the position function when required. These seem to be cripplingly slow for some reason. This readbyte maybe is the problem....
1
by: Keith Kingsley | last post by:
I'm new to C#, so please forgive me if this is elementary. I have a file that consists of, say, one thousand (4-byte) floating points, and I'd like to read it into an array of floats as...
111
by: Tonio Cartonio | last post by:
I have to read characters from stdin and save them in a string. The problem is that I don't know how much characters will be read. Francesco -- ------------------------------------- ...
7
by: Markus Mayer | last post by:
Hi folks. I'm somewhat new to *nix programming and just ran into a problem. I have to take user input from the terminal but like to constrain that to some rules given, i.e. "numbers only" or...
6
by: sapsi | last post by:
Hello, I am using HadoopStreaming using a BinaryInputStream. What this basically does is send a stream of bytes ( the java type is : private byte bytes) to my python program. I have done a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.