Closed auouymous closed 2 months ago
write
is a syscall and is significantly slower than a function call, because it enters the kernel.
#include <unistd.h>
int main(){
for(int i = 0; i < 100000; i++){
#ifdef FAST
write(1, "..", 2);
#else
write(1, ".", 1); write(1, ".", 1);
#endif
}
write(1, "\n", 1);
}
cc -DFAST write.c && time ./a.out
is twice as fast as cc write.c && time ./a.out
.
cc -DFAST write.c && ./a.out |wc -c
and cc write.c && ./a.out |wc -c
show both as 200001 bytes of output.
I am interested to know if you did testing here. Is this actually any faster?