/* * This file is part of solvar. (https://git.redxen.eu/caskd/solvar) * Copyright (c) 2022 Alex-David Denes * * solvar is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * solvar is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with solvar. If not, see . */ package solvar import ( "math/rand" "testing" ) func BenchmarkSolve(b *testing.B) { frand := rand.New(rand.NewSource(100)) var g DependencyGraph idpool := make([]([]byte), frand.Intn(256*256)) for pidx := range idpool { idpool[pidx] = make([]byte, 4) frand.Read(idpool[pidx]) } for range idpool { var o Object for i := 0; i < frand.Intn(256); i++ { o.Id = append(o.Id, Identifier(idpool[frand.Intn(len(idpool))])) } for rid := 0; rid < frand.Intn(256); rid++ { o.Rel = append(o.Rel, Relation{ T: func() RelationType { if (frand.Intn(2))%2 == 0 { return RelationTypeNeed } else { return RelationTypeReject } }(), Id: Identifier(idpool[frand.Intn(len(idpool))]), }) } g.Add(o) } var c struct { o int i int r struct{ n, r int } } c.o = len(g.ol) for _, v := range g.ol { c.i += len(v.Id) for _, vol := range v.Rel { if vol.T == RelationTypeNeed { c.r.n += 1 } else { c.r.r += 1 } } } g.BuildCache() b.Logf("Benchmarking Solve() with %v Objects, %v Idenitifers and Relations with %v Need %v Reject", c.o, c.i, c.r.n, c.r.r) b.ResetTimer() // Setup time for i := 0; i < b.N; i++ { _, err := g.Solve(Identifier(idpool[0])) if err != nil { b.Fatal("Failed to solve:", idpool[0], err) } } }