Add benchmarking for searching for #202

This commit is contained in:
David Dworken 2024-04-14 09:57:44 -07:00
parent 44b4cc6df6
commit 7e4ca84da5
No known key found for this signature in database
2 changed files with 28 additions and 0 deletions

View File

@ -15,6 +15,9 @@ ftest: ## Run a specific test specified via `make ftest FILTER=TestParam/test
go clean -testcache
HISHTORY_FILTERED_TEST=1 TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 gotestsum --packages ./... --rerun-fails=0 --format testname -- -p 1 -run "$(FILTER)" -timeout 60m
fbench: ## Run a specific benchmark test specified via `make fbench FILTER=BenchmarkQuery`
HISHTORY_FILTERED_TEST=1 TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 go test -benchmem -bench "$(FILTER)" -timeout 60m ./...
release: ## [ddworken only] Release the latest version on Github
# Bump the version
expr `cat VERSION` + 1 > VERSION

View File

@ -2977,6 +2977,31 @@ func BenchmarkImport(b *testing.B) {
}
}
func BenchmarkQuery(b *testing.B) {
b.StopTimer()
// Setup with an install with a lot of entries
tester := zshTester{}
defer testutils.BackupAndRestore(b)()
testutils.ResetLocalState(b)
installHishtory(b, tester, "")
numSyntheticEntries := 100_000
createSyntheticImportEntries(b, numSyntheticEntries)
ctx := hctx.MakeContext()
numImported, err := lib.ImportHistory(ctx, false, true)
require.NoError(b, err)
require.GreaterOrEqual(b, numImported, numSyntheticEntries)
// Benchmark it
for n := 0; n < b.N; n++ {
// Benchmarked code:
b.StartTimer()
ctx := hctx.MakeContext()
_, err := lib.Search(ctx, hctx.GetDb(ctx), "echo", 0)
require.NoError(b, err)
b.StopTimer()
}
}
func TestAugmentedIsOfflineError(t *testing.T) {
markTestForSharding(t, 12)
defer testutils.BackupAndRestore(t)()