(b *testing.B)
| 1460 | } |
| 1461 | |
| 1462 | func 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 | } |
nothing calls this directly
no test coverage detected