I/O speed

Henry Cejtin henry@sourcelight.com
Thu, 21 Sep 2000 15:29:04 -0500


Just  to  show you what the competition is, here is what spy says is going on
in a program that is executing the following loop:

    for (;;) {
            ch = getchar();
            if (ch == EOF)
                    break;
            ++size;
    }

    0x8048436:      movl   0x80495b8,%edx
    0x804843c:      movl   0x4(%edx),%eax
    0x804843f:      cmpl   0x8(%edx),%eax
    0x8048442:      jb     0x8048450
    0x8048450:      movzbl (%eax),%eax
    0x8048453:      incl   0x4(%edx)
    0x8048456:      cmpl   $0xffffffff,%eax
    0x8048459:      je     0x8048460
    0x804845b:      incl   %ebx
    0x804845c:      jmp    0x8048436

You can see that it loads a struct pointer into %edx, then  it  compares  two
fields in the struct: one is the pointer to the next location to read and one
is a pointer to the last location you can read.  If the former is  less  than
the latter, it fetches the byte and increments the next location to read.

This  code  is definitely not optimal: you could avoid doing the increment to
memory by incrementing %eax and then just doing a store.  Who knows how  much
difference this makes.