-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile.tmp
More file actions
126 lines (105 loc) · 4.67 KB
/
Makefile.tmp
File metadata and controls
126 lines (105 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
.PHONY: test test-verbose test-coverage test-watch help rg rg-files sd sd-preview sd-in
.PHONY: bench-after
# Default target
help:
@echo "YetiSearch Test Commands:"
@echo ""
@echo " make test Run all tests with simple output"
@echo " make test-verbose Run tests with descriptive output"
@echo " make test-coverage Run tests with coverage report"
@echo " make test-watch Watch for changes and re-run tests"
@echo " make test-unit Run only unit tests"
@echo " make test-filter Run specific test (use TEST=TestName)"
@echo ""
@echo "Developer Shortcuts:"
@echo " make rg PATTERN=... [PATHS=\"src tests\"] # ripgrep search"
@echo " make rg-files PATTERN=... [PATHS=\"src tests\"] # list files matching pattern"
@echo " make sd FROM=... TO=... FILES=\"file1 file2\" [MODE=literal|regex] # replace"
@echo " make sd-preview FROM=... TO=... FILES=\"...\" [MODE=...] # preview replace"
@echo " make sd-in PATTERN=... FROM=... TO=... [PATHS=\"src tests\"] [MODE=...] # replace in files matching PATTERN"
@echo ""
@echo "Benchmarks:"
@echo " make bench-after Run benchmark and save to benchmarks/benchmark-after.txt"
@echo " make bench-before Run legacy benchmark and save to benchmarks/benchmark-before.txt"
@echo " make bench-compare Run both and print delta summary"
bench-after:
@echo "Running benchmark (external-content default) ..."
@rm -f benchmarks/benchmark.db benchmarks/benchmark.db-shm benchmarks/benchmark.db-wal
@php benchmarks/benchmark.php --external=1 | tee benchmarks/benchmark-after.txt
bench-before:
@echo "Running benchmark (legacy schema) ..."
@rm -f benchmarks/benchmark.db benchmarks/benchmark.db-shm benchmarks/benchmark.db-wal
@php benchmarks/benchmark.php --external=0 | tee benchmarks/benchmark-before.txt
# Run all tests
test:
@vendor/bin/phpunit
# Run tests with verbose output
test-verbose:
@vendor/bin/phpunit --testdox --colors=always
# Run tests with coverage
test-coverage:
@XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --colors=always
# Watch for changes
test-watch:
@echo "Watching for changes... (requires phpunit-watcher)"
@vendor/bin/phpunit-watcher watch
# Run only unit tests
test-unit:
@vendor/bin/phpunit --testsuite=Unit --testdox
# Run filtered tests
test-filter:
@vendor/bin/phpunit --testdox --filter="$(TEST)"
# Pretty output
test-pretty:
@php test-runner.php
# ripgrep helpers
RG_PATHS?=src tests
rg:
@rg -n "$(PATTERN)" $(PATHS)
rg-files:
@rg -l "$(PATTERN)" $(PATHS)
# sd helpers (MODE=literal|regex; default literal)
sd:
@if [ -z "$(FROM)" ] || [ -z "$(TO)" ] || [ -z "$(FILES)" ]; then \
echo "Usage: make sd FROM=... TO=... FILES=\"file1 file2\" [MODE=literal|regex]"; exit 1; fi; \
flag="-s"; if [ "$(MODE)" = "regex" ]; then flag=""; fi; \
for f in $(FILES); do sd $$flag "$(FROM)" "$(TO)" "$$f"; done
sd-preview:
@if [ -z "$(FROM)" ] || [ -z "$(TO)" ] || [ -z "$(FILES)" ]; then \
echo "Usage: make sd-preview FROM=... TO=... FILES=\"file1 file2\" [MODE=literal|regex]"; exit 1; fi; \
flag="-s"; if [ "$(MODE)" = "regex" ]; then flag=""; fi; \
for f in $(FILES); do sd -p $$flag "$(FROM)" "$(TO)" "$$f"; done
sd-in:
@if [ -z "$(PATTERN)" ] || [ -z "$(FROM)" ] || [ -z "$(TO)" ]; then \
echo "Usage: make sd-in PATTERN=... FROM=... TO=... [PATHS=\"src tests\"] [MODE=literal|regex]"; exit 1; fi; \
files=`rg -l "$(PATTERN)" $(PATHS)`; \
if [ -z "$$files" ]; then echo "No files matched"; exit 0; fi; \
flag="-s"; if [ "$(MODE)" = "regex" ]; then flag=""; fi; \
for f in $$files; do sd $$flag "$(FROM)" "$(TO)" "$$f"; done
bench-compare:
@$(MAKE) bench-before
@$(MAKE) bench-after
@echo ""
@python3 - << 'PY'
import re
def get(path, key):
with open(path) as f:
for line in f:
if line.startswith(key):
if key == 'Average indexing rate':
return re.sub(',', '', line.split()[3])
return line.split()[2]
return '0'
b='benchmarks/benchmark-before.txt'; a='benchmarks/benchmark-after.txt'
bt=get(b,'Total time'); at=get(a,'Total time')
bi=get(b,'Indexing time'); ai=get(a,'Indexing time')
br=get(b,'Average indexing rate'); ar=get(a,'Average indexing rate')
bm=get(b,'Memory used'); am=get(a,'Memory used')
bp=get(b,'Peak memory'); ap=get(a,'Peak memory')
print('Benchmark comparison (legacy vs external-content)')
print(f"Total time: {bt}s -> {at}s (Δ {float(at)-float(bt):+.4f}s)")
print(f"Indexing time: {bi}s -> {ai}s (Δ {float(ai)-float(bi):+.4f}s)")
print(f"Indexing rate: {br} -> {ar} docs/s (Δ {float(ar)-float(br):+.2f} docs/s)")
print(f"Memory used: {bm} MB -> {am} MB (Δ {float(am)-float(bm):+.2f} MB)")
print(f"Peak memory: {bp} MB -> {ap} MB (Δ {float(ap)-float(bp):+.2f} MB)")
PY