MCPcopy
hub / github.com/google/mangle / BenchmarkJoin

Function BenchmarkJoin

engine/seminaivebottomup_test.go:1462–1492  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1460}
1461
1462func BenchmarkJoin(b *testing.B) {
1463 b.ReportAllocs()
1464 for j := 0; j < b.N; j++ {
1465 // Given two relations has_num(Thing, Num) has_prop(Thing, Property),
1466 // we select from one and join with the other.
1467 program := []ast.Clause{
1468 clause(`foo(X, Prop) :- has_num(X, Num), Num <= 1, has_prop(X, Prop).`),
1469 }
1470 store := factstore.NewIndexedInMemoryStore()
1471 for i := 0; i < 1_000_000; i++ {
1472 id, _ := ast.Name(fmt.Sprintf("/thing/%d", i))
1473 store.Add(ast.NewAtom("has_num", id, ast.Number(int64(i%3))))
1474 store.Add(ast.NewAtom("has_prop", id, ast.String(fmt.Sprintf("/property/%d", i))))
1475 }
1476 programInfo, err := analysis.AnalyzeOneUnit(parse.SourceUnit{Clauses: program}, asMap(store.ListPredicates()))
1477 if err != nil {
1478 b.Fatal(fmt.Errorf("analysis: %w", err))
1479 }
1480 strata, predToStratum, err := analysis.Stratify(analysis.Program{
1481 EdbPredicates: programInfo.EdbPredicates,
1482 IdbPredicates: programInfo.IdbPredicates,
1483 Rules: programInfo.Rules,
1484 })
1485 if err != nil {
1486 b.Fatal(fmt.Errorf("stratification: %w", err))
1487 }
1488 if _, err := EvalStratifiedProgramWithStats(programInfo, strata, predToStratum, store); err != nil {
1489 b.Fatal(fmt.Errorf("evaluation: %w", err))
1490 }
1491 }
1492}

Callers

nothing calls this directly

Calls 12

AddMethod · 0.95
ListPredicatesMethod · 0.95
NewIndexedInMemoryStoreFunction · 0.92
NameFunction · 0.92
NewAtomFunction · 0.92
NumberFunction · 0.92
StringFunction · 0.92
AnalyzeOneUnitFunction · 0.92
StratifyFunction · 0.92
asMapFunction · 0.85
clauseFunction · 0.70

Tested by

no test coverage detected