## Description This PR adds benchmarking capabilities to the lambda interpreter. The benchmarks measure performance across all sample files in the samples folder. This enables consistent performance testing and helps track optimization improvements over time. Changes in this PR: - Added new `bench` target to Makefile for running Go benchmarks. - Created `benchmark_test.go` with sub-benchmarks for each sample file (Church, Fast, Saccharine, Simple, Thunk). - Used `b.Run` for organizing sample-specific sub-benchmarks and `b.Loop` for efficient iteration. - Configured benchmarks to use fixed iterations (10x) and 4 CPU cores for reproducible results. ### Decisions Used `b.Loop()` instead of traditional `for i := 0; i < b.N; i++` pattern. This is the modern Go benchmarking idiom that provides better performance measurement. Benchmarks run the full pipeline (parse, compile, execute, stringify) to measure end-to-end performance for each sample. ## Benefits Provides quantitative performance metrics for the lambda interpreter. Enables tracking performance improvements or regressions across different sample complexities. Consistent benchmark configuration (fixed iterations, CPU cores) ensures reproducible results for comparison. ## Checklist - [x] Code follows conventional commit format. - [x] Branch follows naming convention (`<type>/<description>`). Always use underscores. - [x] Tests pass (if applicable). - [x] Documentation updated (if applicable). Reviewed-on: #14 Co-authored-by: M.V. Hutz <git@maximhutz.me> Co-committed-by: M.V. Hutz <git@maximhutz.me>
48 lines
1.4 KiB
Makefile
48 lines
1.4 KiB
Makefile
BINARY_NAME=lambda
|
|
TEST=simple
|
|
|
|
.PHONY: help build run profile explain graph docs bench clean
|
|
.DEFAULT_GOAL := help
|
|
.SILENT:
|
|
|
|
help:
|
|
echo "Available targets:"
|
|
echo " build - Build the lambda executable"
|
|
echo " run - Build and run the lambda interpreter (use TEST=<name> to specify sample)"
|
|
echo " profile - Build and run with CPU profiling enabled"
|
|
echo " explain - Build and run with explanation mode and profiling"
|
|
echo " graph - Generate and open CPU profile visualization"
|
|
echo " docs - Start local godoc server on port 6060"
|
|
echo " bench - Run benchmarks for all samples"
|
|
echo " clean - Remove all build artifacts"
|
|
|
|
build:
|
|
go build -o ${BINARY_NAME} ./cmd/lambda
|
|
chmod +x ${BINARY_NAME}
|
|
|
|
run: build
|
|
./${BINARY_NAME} -f ./samples/$(TEST).txt -o program.out
|
|
|
|
profile: build
|
|
./${BINARY_NAME} -p profile/cpu.prof -f ./samples/$(TEST).txt -o program.out
|
|
|
|
explain: build
|
|
./${BINARY_NAME} -x -p profile/cpu.prof -f ./samples/$(TEST).txt -o program.out
|
|
|
|
graph:
|
|
go tool pprof -raw -output=profile/cpu.raw profile/cpu.prof
|
|
go tool pprof -svg profile/cpu.prof > profile/cpu.svg
|
|
echo ">>> View at 'file://$(PWD)/profile/cpu.svg'"
|
|
|
|
docs:
|
|
echo ">>> View at 'http://localhost:6060/pkg/git.maximhutz.com/max/lambda/'"
|
|
go run golang.org/x/tools/cmd/godoc@latest -http=:6060
|
|
|
|
bench:
|
|
go test -bench=. -benchtime=10x -cpu=4 ./cmd/lambda
|
|
|
|
clean:
|
|
rm -f ${BINARY_NAME}
|
|
rm -f program.out
|
|
rm -rf profile/
|