473,396 Members | 1,608 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,396 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 6973
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.