News for hackers. Stuff that matters.
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by 3eb7988a1663 on Tuesday May 27, 2025 @01:55AM (#44104252)
That reddit thread has some amazing benchmarks.

The GNU-yes

  $ yes | pv > /dev/null
  ... [10.2GiB/s] ...
The way I (not a C programmer) would have written it

  void main() {
      while(write(1, "y\n", 2)); // 1 is stdout
  }

  $ gcc yes.c -o yes
  $ ./yes | pv > /dev/null
  ... [6.21 MiB/s] ...
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by phh on Tuesday May 27, 2025 @03:43AM (#44104765)
Which implies you get pretty much 3M syscall per second. Which is a good order magnitude to know
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by nasretdinov on Tuesday May 27, 2025 @04:53AM (#44105119)
I don't believe puts is performing unbuffered I/O though. It's a libc function, not a direct syscall. Correct me if I'm wrong of course
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by lieks on Tuesday May 27, 2025 @07:38AM (#44105917)
The write(2) libc function is just a C wrapper for the syscall. It's the functions from stdio.h that are buffered.
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by nasretdinov on Tuesday May 27, 2025 @08:26AM (#44106261)
Ah ok sorry I got confused by the comments nesting level. I thought we were talking about the OpenBSD's version which uses puts
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by pona-a on Tuesday May 27, 2025 @04:23AM (#44104963)
As a non-system-programmer, here's my attempt in Odin.

  yes | pv > /dev/null
  0:00:15 [1.12GiB/s]
  build/yes | pv > /dev/null
  0:00:20 [1.03GiB/s]


  package main
  
  import "core:sys/linux"
  import "core:os"
  import "core:strings"
  
  main :: proc() {
    msg := "y" if len(os.args) == 1 else os.args[1]
    msg = strings.concatenate({msg, "\n"})
  
    buf := transmute([]u8) strings.repeat(msg, 8192)
    for {
      linux.write(linux.STDOUT_FILENO, buf)
    }
  }
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by forgotpwd16 on Tuesday May 27, 2025 @04:50AM (#44105104)
Replace `write(..)` with `puts("y")` and you'll be an order of magnitude faster. This is due to `puts` (`printf` too) being buffered (data isn't written to term/file immediately but retained in memory until some point). Improving this process (as seen in the reddit thread) gets GNU-yes.
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by GoblinSlayer on Tuesday May 27, 2025 @05:01AM (#44105158)
It's line buffered when it prints to terminal.
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by jesprenj on Tuesday May 27, 2025 @07:38AM (#44105923)
One rarely needs yes' output to be a terminal.
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by throwawaymaths on Tuesday May 27, 2025 @05:35AM (#44105347)
Don't you actively want it to flush asap since you're usually piping into another program?

I suspect what you suggest creates a more voluminous dump but is slower in the desired use case

Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by Macha on Tuesday May 27, 2025 @06:39AM (#44105616)
If you compile your variant with -O3 I imagine it will be much faster? Iirc, the default is for GCC is to not optimise
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by imurray on Tuesday May 27, 2025 @08:17AM (#44106198)
No, it will be about the same. The algorithm is wrong (calling write repeatedly) and -O3 isn't sufficient to rewrite that.
Re:Yes-rs: A fast, memory-safe rewrite of the classic Unix y... by aequitas on Tuesday May 27, 2025 @01:36PM (#44109041)

  yes &
A few times is still my favorite way to push a cpu to max temperature for testing. Used it a lot to detect faulty Core 2 Duo MacBook back in the day. They would short circuit some CPU sensor due to thermal expansion or melting of the wire insulation. Yes was an easy way to get the CPU’s hot enough.