feat: add benchmarking stdlib with memory safety checks and example scripts
Implement a new `benchmark` standard library module providing high-precision nanosecond timing functions (`bench_start`, `bench_end`, `bench_format`, `bench_format_auto`, `bench_reset`). Add a dedicated `memory.c` module with runtime memory safety validation, including stack overflow detection, local variable limit enforcement, and high-water mark tracking. Integrate memory checks into the interpreter's variable declaration path in `src/interpreter.c` and initialize the memory subsystem in `src/main.c`. Update the build system (`Makefile`) to compile the new source files and include benchmark tests in the test suite. Extend `TUTORIAL.md` with comprehensive documentation for the benchmarking API and random number functions (`rand`, `srand`, `rand_range`, `time`). Add two example scripts (`examples/bench.rc` and `examples/benchmark_demo.rc`) demonstrating performance measurement of recursive Fibonacci, loop iterations, list operations, string concatenation, object creation, and sorting algorithms.
This commit is contained in:
@@ -22,6 +22,7 @@ SOURCES = $(SRC_DIR)/main.c \
|
||||
$(SRC_DIR)/error.c \
|
||||
$(SRC_DIR)/context.c \
|
||||
$(SRC_DIR)/debug.c \
|
||||
$(SRC_DIR)/memory.c \
|
||||
$(SRC_DIR)/stdlib/stdlib.c \
|
||||
$(SRC_DIR)/stdlib/string/string_stdlib.c \
|
||||
$(SRC_DIR)/stdlib/math/math_stdlib.c \
|
||||
@@ -30,6 +31,7 @@ SOURCES = $(SRC_DIR)/main.c \
|
||||
$(SRC_DIR)/stdlib/async/async_stdlib.c \
|
||||
$(SRC_DIR)/stdlib/constants/constants_stdlib.c \
|
||||
$(SRC_DIR)/stdlib/eval/eval_stdlib.c \
|
||||
$(SRC_DIR)/stdlib/benchmark/benchmark_stdlib.c \
|
||||
|
||||
OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
|
||||
|
||||
@@ -41,6 +43,7 @@ TESTS = $(TEST_DIR)/unittest.rc \
|
||||
$(TEST_DIR)/test_stdlib_socket.rc \
|
||||
$(TEST_DIR)/test_stdlib_async.rc \
|
||||
$(TEST_DIR)/test_stdlib_constants.rc \
|
||||
$(TEST_DIR)/test_stdlib_benchmark.rc \
|
||||
$(TEST_DIR)/test_oop.rc \
|
||||
$(TEST_DIR)/test_preprocessor.rc \
|
||||
$(TEST_DIR)/test_eval.rc \
|
||||
@@ -64,6 +67,7 @@ dirs:
|
||||
@mkdir -p $(BUILD_DIR)/stdlib/async
|
||||
@mkdir -p $(BUILD_DIR)/stdlib/constants
|
||||
@mkdir -p $(BUILD_DIR)/stdlib/eval
|
||||
@mkdir -p $(BUILD_DIR)/stdlib/benchmark
|
||||
|
||||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@@ -80,37 +84,40 @@ test: $(TARGET)
|
||||
@echo " RC LANGUAGE - COMPREHENSIVE TEST SUITE"
|
||||
@echo "================================================================"
|
||||
@echo ""
|
||||
@echo "[1/11] Running Language Features Tests..."
|
||||
@echo "[1/12] Running Language Features Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_language_features.rc
|
||||
@echo ""
|
||||
@echo "[2/11] Running String Standard Library Tests..."
|
||||
@echo "[2/12] Running String Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_string.rc
|
||||
@echo ""
|
||||
@echo "[3/11] Running Math Standard Library Tests..."
|
||||
@echo "[3/12] Running Math Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_math.rc
|
||||
@echo ""
|
||||
@echo "[4/11] Running I/O Standard Library Tests..."
|
||||
@echo "[4/12] Running I/O Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_io.rc
|
||||
@echo ""
|
||||
@echo "[5/11] Running Socket Standard Library Tests..."
|
||||
@echo "[5/12] Running Socket Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_socket.rc
|
||||
@echo ""
|
||||
@echo "[6/11] Running Async Standard Library Tests..."
|
||||
@echo "[6/12] Running Async Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_async.rc
|
||||
@echo ""
|
||||
@echo "[7/11] Running Constants Standard Library Tests..."
|
||||
@echo "[7/12] Running Constants Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_constants.rc
|
||||
@echo ""
|
||||
@echo "[8/11] Running OOP Features Tests..."
|
||||
@echo "[8/12] Running Benchmark Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_benchmark.rc
|
||||
@echo ""
|
||||
@echo "[9/12] Running OOP Features Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_oop.rc
|
||||
@echo ""
|
||||
@echo "[9/11] Running Preprocessor Tests..."
|
||||
@echo "[10/12] Running Preprocessor Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_preprocessor.rc
|
||||
@echo ""
|
||||
@echo "[10/11] Running Eval Function Tests..."
|
||||
@echo "[11/12] Running Eval Function Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_eval.rc
|
||||
@echo ""
|
||||
@echo "[11/11] Running Input Validation Tests..."
|
||||
@echo "[12/12] Running Input Validation Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_input_validation.rc
|
||||
@echo ""
|
||||
@echo "================================================================"
|
||||
@@ -153,6 +160,9 @@ test-validation: $(TARGET)
|
||||
test-constants: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_stdlib_constants.rc
|
||||
|
||||
test-benchmark: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_stdlib_benchmark.rc
|
||||
|
||||
test-robustness: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_robustness.rc
|
||||
|
||||
@@ -187,7 +197,7 @@ help:
|
||||
@echo ""
|
||||
@echo "Usage:"
|
||||
@echo " make - Build the interpreter"
|
||||
@echo " make test - Run ALL comprehensive tests (250+ tests)"
|
||||
@echo " make test - Run ALL comprehensive tests (300+ tests)"
|
||||
@echo " make test-smoke - Run quick smoke test (31 tests)"
|
||||
@echo " make clean - Remove all build artifacts"
|
||||
@echo ""
|
||||
@@ -199,6 +209,7 @@ help:
|
||||
@echo " make test-socket - Socket stdlib (19 tests)"
|
||||
@echo " make test-async - Async stdlib (37 tests)"
|
||||
@echo " make test-constants - Constants stdlib (13 tests)"
|
||||
@echo " make test-benchmark - Benchmark stdlib (50 tests)"
|
||||
@echo " make test-oop - OOP features (31 tests)"
|
||||
@echo " make test-preprocessor - Preprocessor (2 tests)"
|
||||
@echo " make test-eval - Eval function (30 tests)"
|
||||
@@ -224,6 +235,7 @@ help:
|
||||
@echo " stdlib/io/ - I/O functions"
|
||||
@echo " stdlib/async/ - Async functions"
|
||||
@echo " stdlib/eval/ - Eval function"
|
||||
@echo " stdlib/benchmark/ - Benchmarking functions"
|
||||
@echo " tests/ - Test programs (unittest framework)"
|
||||
@echo " examples/ - Example programs (.rc files)"
|
||||
@echo " build/ - Compiled object files"
|
||||
|
||||
Reference in New Issue
Block a user