donniebreve / touchcursor-linux

TouchCursor style keyboard remapping for Linux.
GNU General Public License v2.0
133 stars 28 forks source link

Reduce emit latency by using a single write call #79

Closed auouymous closed 2 months ago

donniebreve commented 2 months ago

I am interested to know if you did testing here. Is this actually any faster?

auouymous commented 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.