From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9c86eb13dd395066 X-Google-Attributes: gid103376,public From: dbrown@vigra.com (David Brown) Subject: Re: CRC in Ada? Date: 1997/03/07 Message-ID: #1/1 X-Deja-AN: 223805117 Sender: dbrown@ted.vigra.com References: <1997Mar2.220652@nova.wright.edu> Organization: VisiCom Laboratories, Inc. Newsgroups: comp.lang.ada Date: 1997-03-07T00:00:00+00:00 List-Id: ohk@edeber.tfdt-o.nta.no (Ole-Hjalmar Kristensen FOU.TD/DELAB) writes: > char buf[4096]; > > main() { > int c,n,total=0; > while ((n = read(0,buf,sizeof(buf))) > 0) { > int i; > for (i = 0; i < n; i++) { > c = buf[i]; > total++; > } > } > printf("total %d\n",total); > } > > Average results obtained with time: > 0.12u 0.29s 0:00.41 100.0% > > It is somewhat surprising that the difference between the user CPU > times is so large, but I'm more surprised by the speed of the second > version than by the slowness of the first. I suspect that most of the inner loop is being optimized out. Since you don't actually do anything with 'c', it probably is never actually used. The buffer is probably never accessed. A slightly better test would be to compute a simple checksum or something. Dave Brown dbrown@vigra.com