add benchmarks
[haskell/symantic-parser.git] / Makefile
index ad5e24d3d20660cb5b5dd4c036efb3b9160d689f..3baf6313b82381ac9e54144cb216037e76456596 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,29 +1,73 @@
-cabal = $(wildcard *.cabal)
-package = $(notdir ./$(cabal:.cabal=))
-version = $(shell sed -ne 's/^version: *\(.*\)/\1/p' $(cabal))
+override RTS_OPTIONS += -L100
+override TEST_OPTIONS += --color always --size-cutoff 1000000 $(addprefix -p ,$t)
+override GHC_PROF_OPTIONS += -fprof-auto -fprof-auto-calls
+override BENCHMARK_OPTIONS += --output benchmarks/html/$(version).html --match glob $b
+
+cabal := $(wildcard *.cabal)
+package := $(notdir ./$(cabal:.cabal=))
+version := $(shell sed -ne 's/^version: *\(.*\)/\1/p' $(cabal))
+project := $(patsubst %.cabal,%,$(cabal))
+
 all: build
 build:
        cabal build
 clean c:
        cabal clean
 repl:
-       cabal repl
+       cabal repl $(project)
+parsers/repl:
+       cabal repl $(project):parsers
 
-t:
-       cabal test $(TESTFLAGS) --test-show-details always --test-options "$(TESTOPTIONS) --color always --size-cutoff 1000000 $${p:+-p $$p}"
-%/accept: TESTOPTIONS+=--accept
+tests:
+       cabal test $(CABAL_TEST_FLAGS) \
+        --test-show-details always --test-options "$(TEST_OPTIONS)"
+tests/prof-time: $(project)-test.eventlog.json
+tests/prof-heap: $(project)-test.eventlog.html
+.PHONY: $(project)-test.eventlog
+$(project)-test.eventlog $(project)-test.prof:
+       cabal test $(CABAL_TEST_FLAGS) \
+        --test-show-details always --test-options "$(TEST_OPTIONS) +RTS $(RTS_OPTIONS)" \
+        --enable-profiling $(GHC_PROF_OPTIONS) || true
+tests/prof-th:
+       cabal v2-build lib:$(project) --enable-profiling $(GHC_PROF_OPTIONS) --write-ghc-environment-files=always
+       cabal test $(CABAL_TEST_FLAGS) \
+        --test-show-details always --test-options "$(TEST_OPTIONS) +RTS $(RTS_OPTIONS)" \
+        --enable-profiling $(GHC_PROF_OPTIONS) \
+        --ghc-options "$(addprefix -opti,+RTS $(RTS_OPTIONS))"
+tests/repl:
+       cabal repl --enable-tests $(project)-test
+
+%/accept: TEST_OPTIONS += --accept
 %/accept: %
        
-%/cover: TESTFLAGS+=--enable-coverage
+%/cover: CABAL_TEST_FLAGS += --enable-coverage
 %/cover: %
        
-t/prof:
-       cabal v2-build lib:symantic-parser --enable-profiling --write-ghc-environment-files=always
-       cabal test $(TESTFLAGS) --enable-profiling -fprof-auto -fprof-auto-calls \
-        --test-show-details always --test-options "$(TESTOPTIONS) $${p:+-p $$p}" \
-        --ghc-options "-opti+RTS -opti-p -opti-L100 -opti-ls -opti-xc"
-t/repl:
-       cabal repl --enable-tests symantic-parser-test
+%.eventlog.html: RTS_OPTIONS += -hy -l-au
+%.eventlog.html: %.eventlog
+       eventlog2html $<
+%.eventlog.json: RTS_OPTIONS += -p -l-au
+%.eventlog.json: %.eventlog
+       hs-speedscope $<
+
+b benchmarks/html/$(version).html:
+       mkdir -p benchmarks/html
+       cabal bench $(CABAL_BENCH_FLAGS) --benchmark-options "$(BENCHMARK_OPTIONS)"
+benchmarks/repl:
+       cabal repl --enable-benchmarks $(project)-benchmark
+benchmarks/prof-time: $(project)-benchmark.eventlog.json
+benchmarks/prof-heap: $(project)-benchmark.eventlog.html
+.PHONY: $(project)-benchmark.eventlog
+$(project)-benchmark.eventlog $(project)-benchmark.prof:
+       cabal bench $(CABAL_BENCH_FLAGS) \
+        --benchmark-options "$(BENCHMARK_OPTIONS) +RTS $(RTS_OPTIONS)" \
+        --enable-profiling $(GHC_PROF_OPTIONS)
+$(project)-benchmark.prof2:
+       cabal v2-build lib:$(project) --enable-profiling $(GHC_PROF_OPTIONS) --write-ghc-environment-files=always
+       cabal bench $(CABAL_BENCH_FLAGS) \
+        --benchmark-options "$(BENCHMARK_OPTIONS)" \
+        --enable-profiling $(GHC_PROF_OPTIONS) \
+        --ghc-options "$(addprefix -opti,+RTS $(RTS_OPTIONS))"
 
 doc:
        cabal haddock --haddock-css ocean --haddock-hyperlink-source