Date: Mon, 5 Feb 2001 10:52:42 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: lauras AT softhome DOT net cc: djgpp-workers AT delorie DOT com Subject: Re: stdint.h In-Reply-To: <20010204104132.7148.qmail@softhome.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Sun, 4 Feb 2001 lauras AT softhome DOT net wrote: > Eli Zaretskii writes: > > However, I didn't find any evidence that an int is faster than a char. > > Can you provide such an evidence, e.g., by looking at the code produced > > by gcc 2.9X and counting cycles? > > I tried. I was wrong - the difference between two versions is very little. > > Here is my "benchmark": > > int main(void) > { > unsigned char x, y, z, t, u, v; > for (x = 0; x < 200; x++) > for (y = 0; y < 200; y++) > for (u = 0; u < 200; u++) > for (v = 0; v < 200; v++) > { > z = x * y; > t = z - x / y; > z = t + u; > t = z - u; > } > return 0; > } This program divides by zero (when y == 0), so its precise timing is extremely system-dependent (on some systems, it crashes right away). It also throws away the results of the computations, so a really smart compiler could transform it into a no-op. I modified the program as shown below (removing the unsigned qualifier while I was at it, to let the compiler work with processor's native data types), and the results on a P166 were: int version: 41 seconds short version: 45 seconds char version: 36 seconds int main(void) { char x, y, z, t, u, v; for (x = 0; x < 100; x++) for (y = 1; y < 101; y++) for (u = 0; u < 100; u++) for (v = 0; v < 100; v++) { z = x * y; t = z - x / y; z = t + u; t = z - u; } return t; }