Click here to Skip to main content
15,916,042 members
Home / Discussions / C#
   

C#

 
GeneralRe: DateTime.Now Pin
DaveyM6911-Jun-08 0:41
professionalDaveyM6911-Jun-08 0:41 
GeneralRe: DateTime.Now Pin
George_George11-Jun-08 1:33
George_George11-Jun-08 1:33 
GeneralRe: DateTime.Now Pin
DaveyM6911-Jun-08 2:37
professionalDaveyM6911-Jun-08 2:37 
GeneralRe: DateTime.Now Pin
George_George11-Jun-08 16:31
George_George11-Jun-08 16:31 
GeneralRe: DateTime.Now Pin
DaveyM6912-Jun-08 0:39
professionalDaveyM6912-Jun-08 0:39 
GeneralRe: DateTime.Now Pin
George_George12-Jun-08 1:29
George_George12-Jun-08 1:29 
GeneralRe: DateTime.Now Pin
Guffa11-Jun-08 2:19
Guffa11-Jun-08 2:19 
GeneralRe: DateTime.Now Pin
George_George11-Jun-08 1:28
George_George11-Jun-08 1:28 
GeneralRe: DateTime.Now Pin
George_George11-Jun-08 1:26
George_George11-Jun-08 1:26 
AnswerRe: DateTime.Now Pin
#realJSOP10-Jun-08 6:29
professional#realJSOP10-Jun-08 6:29 
GeneralRe: DateTime.Now Pin
George_George11-Jun-08 1:40
George_George11-Jun-08 1:40 
Questionasynchronous function callback Pin
George_George9-Jun-08 17:14
George_George9-Jun-08 17:14 
AnswerRe: asynchronous function callback Pin
N a v a n e e t h11-Jun-08 16:22
N a v a n e e t h11-Jun-08 16:22 
GeneralRe: asynchronous function callback Pin
George_George11-Jun-08 16:34
George_George11-Jun-08 16:34 
QuestionWill Using Console.Beep(); Too Much Damage Your Computer? Pin
qszwdxefc9-Jun-08 16:59
qszwdxefc9-Jun-08 16:59 
AnswerRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
Christian Graus9-Jun-08 17:16
protectorChristian Graus9-Jun-08 17:16 
JokeRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
PIEBALDconsult9-Jun-08 17:26
mvePIEBALDconsult9-Jun-08 17:26 
GeneralRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
MarkB7779-Jun-08 17:49
MarkB7779-Jun-08 17:49 
AnswerRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
Joe Woodbury9-Jun-08 19:30
professionalJoe Woodbury9-Jun-08 19:30 
AnswerRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
Ashfield9-Jun-08 21:24
Ashfield9-Jun-08 21:24 
QuestionBind a Datatable With an Hyperlink Column To a GridView Pin
HatakeKaKaShi9-Jun-08 16:51
HatakeKaKaShi9-Jun-08 16:51 
QuestionBinary Reader Scanning for string Pin
Jammer9-Jun-08 15:12
Jammer9-Jun-08 15:12 
AnswerRe: Binary Reader Scanning for string Pin
Insincere Dave9-Jun-08 17:21
Insincere Dave9-Jun-08 17:21 
I don't think the code you posted is that bad. You could improve it a little by keeping track of the previous characters so you don't need to reset the position. I did some unscientific tests using a 20mb MemoryStream with the data part at the end.

Original 1x
Keep track of previous characters using an array like a circular queue. ~1.8x speedup
Same as above but treating characters as bytes. ~8x speedup to original
Read whole file into byte[]. ~20x speedup

long pos = 0;
byte[] previous = bReader.ReadBytes(4);

for (long i = bReader.BaseStream.Position; i < length; i++)
{
    byte current = bReader.ReadByte();
    previous[pos++ % 4] = current;

    if (previous[pos % 4] == 'd' && previous[(pos + 1) % 4] == 'a' && previous[(pos + 2) % 4] == 't' && previous[(pos + 3) % 4] == 'a')
    {
        dataChunk.sChunkID = "data";
        dataChunk.dwChunkSize = bReader.ReadUInt32();
        return;
    }
}


It would seem the text encoding has the biggest impact, I couldn't find many wav files to test so I don't know if my code behaves any better than yours does, of the ones I tested the actual speed impact was negligible maybe something else was causing the slowdown?
Check the files that aren't working in a hex editor (in VS Open File > Open Dropdown > Binary Editor) and make sure you take care between int/unit/long for positions, file lengths e.t.c and the endianess of what your reading.

Think you've already seen this article.
GeneralRe: Binary Reader Scanning for string Pin
Jammer10-Jun-08 3:22
Jammer10-Jun-08 3:22 
AnswerRe: Binary Reader Scanning for string Pin
Guffa10-Jun-08 12:02
Guffa10-Jun-08 12:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.