A multi-language implementation of the Unix yes command utility.
This project implements the classic Unix yes command in multiple programming languages. The yes utility outputs a string repeatedly until killed, which is useful for automatically responding to prompts in scripts.
Each implementation follows the same basic behavior:
- Without arguments, outputs "y" repeatedly
- With an argument, outputs that argument repeatedly
- Continues until terminated (e.g., with Ctrl+C)
The project currently includes implementations in the following languages:
| Language | File | Features |
|---|---|---|
| C | yes.c |
Simple implementation using printf |
| Go | yes.go |
Clean implementation with fmt package |
| Rust | yes.rs |
Buffered output for performance |
| Swift | yes.swift |
Basic implementation using print |
| Objective-C | yes.m |
Uses Foundation framework and autoreleasepool |
| V | yes.v |
Modern implementation in V language |
| Zig | yes.zig |
Basic implementation |
| Zig (buf) | yes_buf.zig |
Buffered writer for improved performance |
| Zig (buf-2) | yes_buf-2.zig |
Advanced buffer optimization strategy |
| Nim | yes.nim |
Simple implementation |
| Julia | yes.jl |
Concise implementation |
Ensure you have the following compilers/tools installed:
- C:
clangorgcc - Go:
gocompiler - Rust:
rustc - Swift:
swiftc - Objective-C:
clangwith Objective-C support - V:
vcompiler - Zig:
zigcompiler - Nim:
nimcompiler - Julia:
juliainterpreter (for running the script)
Use the provided Makefile to build all implementations:
make allThis will create compiled binaries in the bin/ directory.
To build a specific language implementation:
make c # Build C version
make go # Build Go version
make rust # Build Rust version
make swift # Build Swift version
make oc # Build Objective-C version
make v # Build V version
make zig # Build all Zig versions
make nim # Build Nim versionFor Zig, you can build specific variants:
make zig-basic # Basic Zig implementation
make zig-buf # Buffered Zig implementation
make zig-buf-2 # Advanced buffered Zig implementationTo remove all compiled binaries:
make cleanYou can test the performance of each implementation using the pv utility (pipe viewer):
./bin/yes-c | pv -r > /dev/null
./bin/yes-go | pv -r > /dev/null
./bin/yes-rs | pv -r > /dev/null
# etc.The -r flag for pv shows the rate of data throughput, which helps compare the performance of different implementations.
Several implementations use different optimization strategies:
-
Basic Output: Simple implementations (C, Go, Swift, V, Julia) use standard output functions without special optimization.
-
Buffered Output: The Rust implementation and some Zig variants use buffered writers to reduce system call overhead.
-
Advanced Buffering: The
yes_buf-2.zigimplementation uses an exponential buffer filling strategy to maximize throughput by:- Pre-filling a buffer with repeated copies of the output string
- Doubling the content each iteration until the buffer is filled
- Writing the entire buffer at once to minimize system calls
Contributions are welcome! Here are some ways to contribute:
- Add implementations in other programming languages
- Improve existing implementations for better performance
- Add more comprehensive benchmarking tools
- Improve documentation
When contributing:
- Follow the existing code style
- Ensure your implementation handles command-line arguments correctly
- Add build instructions to the Makefile
- Update this README with details about your implementation
This project is open source and available under standard open source licenses.