Skip to content

liut/yes

Repository files navigation

yes

A multi-language implementation of the Unix yes command utility.

Overview

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)

Implementations

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

Build Instructions

Prerequisites

Ensure you have the following compilers/tools installed:

  • C: clang or gcc
  • Go: go compiler
  • Rust: rustc
  • Swift: swiftc
  • Objective-C: clang with Objective-C support
  • V: v compiler
  • Zig: zig compiler
  • Nim: nim compiler
  • Julia: julia interpreter (for running the script)

Building All Implementations

Use the provided Makefile to build all implementations:

make all

This will create compiled binaries in the bin/ directory.

Building Specific Implementations

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 version

For 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 implementation

Cleaning Build Artifacts

To remove all compiled binaries:

make clean

Performance Testing

You 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.

Optimization Strategies

Several implementations use different optimization strategies:

  1. Basic Output: Simple implementations (C, Go, Swift, V, Julia) use standard output functions without special optimization.

  2. Buffered Output: The Rust implementation and some Zig variants use buffered writers to reduce system call overhead.

  3. Advanced Buffering: The yes_buf-2.zig implementation 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

Contributing

Contributions are welcome! Here are some ways to contribute:

  1. Add implementations in other programming languages
  2. Improve existing implementations for better performance
  3. Add more comprehensive benchmarking tools
  4. 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

License

This project is open source and available under standard open source licenses.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published