>decide to test random things with pv
>gnu yes is fucking retardedly fast (~6GiB/s) given how completely BLOAT the source code looks
>3 levels of header autism to obfuscate a fucking write() call
>try naively writing my own yes
>hella slow (~100MiB/s)
>copy random BSD and Sun yes.c's
>virtually the same as mine.
wtf /g/, I thought bloat was bad.
>>60877367
autism thread?BITS 64
CPU X64
global _start
section .text
_start:
inc rdi ; stdout, will not change after syscall
mov rsi, y ; will not change after syscall
mov rdx, 8192 ; will not change after syscall
_loop:
mov rax, 1 ; sys_write
syscall
jmp _loop
y: times 4096 db "y", 0xA
autism thread.
>>60877395
it doesn't work$ ./a.out test
y
y
y
y
y
it only outputs y
>>60877418
that's the point
fix it yourself if you want arguments
>>60877429
whatever I think i figured it out// adjust to fit the file descriptor buffering in your kernel
#define TOTAL 32768
// output y\n as fast as possible to stdout
// or output whatever string the user provides
int main(int argc, char* argv[]) {
// remove calling name
argc--; argv++;
// default values
size_t LEN = 2;
char* yes = "y\n";
// handle args
if (argc > 0) {
// TOTAL less one for space for \n
LEN = strnlen(argv[0], TOTAL-1) + 1;
yes = argv[0]; // new string
// we don't need a \0 anyhow
yes[LEN-1] = '\n';
}
// alloc buffer with zeros statically
char buf[TOTAL] = { 0 };
// track location in buffer
size_t bufused = 0;
// copy string to fill buffer
while (bufused+LEN <= TOTAL) {
memcpy(buf+bufused, yes, LEN);
bufused += LEN;
}
// print forever bro
while (write(1, buf, bufused) == bufused) {}
// tf bro
return 1;
}
I guess stdio is just shit.
>>60877470└─> ./muh-yes-muhfugga | pv >/dev/null
^C.6GiB 0:00:04 [6.76GiB/s] [ <=> ]
how underwhelming...I thought it was some weird gnu magic.