ReadByte length - DICOM

This is a discussion on ReadByte length - DICOM ; Hi there, I'm a newbie on C# and I was trying just to open a file, read it byte-a-byte and close controlling the length of this operation. Doing that with a 500Kb file I get a duration of about 3,5 ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: ReadByte length

  1. ReadByte length

    Hi there,

    I'm a newbie on C# and I was trying just to open a file, read it
    byte-a-byte and close controlling the length of this operation. Doing
    that with a 500Kb file I get a duration of about 3,5 seconds and doing
    it on a 8Mb file i get 55 seconds!!. Is that ok??, or is something
    wrong...I guess that is too much time, I expect having a lower times,
    but don't know. See code:

    DateTime start = DateTime.Now;

    string fileName = args[0];
    FileInfo file = new FileInfo( fileName );
    Stream buff = new BufferedStream( new FileStream( file.FullName,
    FileMode.Open,
    FileAccess.Read ));
    BinaryReader ins = new BinaryReader(buff);

    while ( (ins.BaseStream.Position) < ins.BaseStream.Length )
    {
    ins.ReadByte();
    }
    buff.Close();
    TimeSpan total = DateTime.Now.Subtract( start );
    Console.WriteLine( "time length=
    "+total.TotalMilliseconds.ToString());

  2. Re: ReadByte length

    Reading byte for byte is NOT the fastest way to read a DICOM file (in
    any language). The overhead of the call into the stream code becomes
    very large compared to the moved bytes (in your case 1). Why not try
    to read the file with something like 64K byte buffers?

+ Reply to Thread