more questions about efficient C code
shekita at crystal.UUCP
shekita at crystal.UUCP
Sat Jun 22 04:18:14 AEST 1985
I am currently modifying C code, written by someone else,
that is incredibly terse. It's paramount that the code
be fast, so I presume the code is terse for speed. I'm
now curious about a few things:
1) Is the "var = (bool expr) ? : expr1 : expr2" construct faster
than just a good old if statement?
2) Are for loops faster than while loops?
3) Is there really much to be gained by using assignment within
a boolean expression, for example, is
if ((fp = fopen("foo", "r") == NULL) {
...
}
really that much faster than
fp = fopen("foo", "r");
if (fp == NULL) {
...
}
4) Are tests for zero more efficently written as
if (var) {
...
}
rather than as
if (var != 0) {
...
}
More information about the Comp.lang.c
mailing list