Skip to content

Conversation

@vinitkumar
Copy link
Owner

@vinitkumar vinitkumar commented Jan 12, 2026

This commit introduces a complete Zig implementation of the chatbot alongside
the original C version, with a focus on learning Zig and comparing the two
implementations.

Key Changes

Zig Implementation

  • Implement hash table data structure with create, set, get, and destroy operations
  • Port chatbot logic from C to Zig with proper memory management using allocators
  • Add comprehensive test suite (5 tests covering hash table operations)
  • Both C and Zig versions produce identical output for the same inputs

Project Structure

  • Reorganize C and Zig implementations into separate directories:
    • c/: Original C implementation with Makefile
    • zig/: Zig port with build.zig configuration
  • Add root-level README with building and testing instructions for both versions

CI/CD

  • Add GitHub Actions workflow (.github/workflows/zig.yml) that:
    • Builds C version using gcc
    • Builds and tests Zig version (Zig 0.15.2)
    • Validates both executables run successfully

Benchmarking

  • Add build-time benchmark (benchmark.sh) comparing compilation speed and binary size

    • C: 93ms build time, 33K executable
    • Zig: 710ms build time, 1.3M executable (C is 7.63x faster)
  • Add runtime benchmark (run_benchmarks.sh) comparing execution performance

    • Builds both versions, runs with identical test inputs (test_inputs.txt)
    • Validates output equivalence between implementations
    • C: 286ms execution time, 1.83x faster than Zig
  • Add BENCHMARK.md with detailed analysis of build metrics

Documentation

  • Add zig/README.md with Zig-specific build and test instructions
  • Update root README with:
    • Benchmarking results summary and tables
    • Instructions for running both build and runtime benchmarks
    • Building instructions for C and Zig versions separately

Build Artifacts

  • Update .gitignore to exclude Zig build artifacts (.zig-cache/, zig-out/)

Testing & Validation

  • All 5 Zig tests pass (hash table operations)
  • Both C and Zig versions produce identical output for test inputs
  • CI runs on both main and zig-port branches

@vinitkumar vinitkumar changed the title Zig port Port chatbot from C to Zig with comprehensive benchmarking Jan 12, 2026
Remove @cImport usage that required libc linking and replace with
native Zig 0.15 I/O API using explicit buffer management. Also update
build.zig to use the new createModule() API required by Zig 0.15.
@vinitkumar vinitkumar merged commit 1d093b6 into main Jan 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants