MCPcopy
hub / github.com/rh12503/triangula / BenchmarkAlgorithm

Function BenchmarkAlgorithm

algorithm/algorithm_test.go:20–62  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

18)
19
20func BenchmarkAlgorithm(b *testing.B) {
21 rand.Seed(time.Now().UnixNano())
22 random.Seed(time.Now().UnixNano())
23
24 file, err := os.Open("../imgs/clown.jpg")
25
26 if err != nil {
27 panic(err)
28 }
29
30 imageFile, _, err := image.Decode(file)
31
32 file.Close()
33
34 if err != nil {
35 log.Fatal(err)
36 }
37
38 imgData := imageData.ToData(imageFile)
39
40 if err != nil {
41 log.Fatal("Arg #2 not an integer")
42 }
43
44 pointFactory := func() normgeom.NormPointGroup {
45
46 return (generator.RandomGenerator{}).Generate(1000)
47 }
48 evaluatorFactory := func(n int) evaluator.Evaluator {
49 return evaluator.NewParallel(fitness.TrianglesImageFunctions(imgData, 5, n), 22)
50 }
51
52 mutator := mutation.NewGaussianMethod(2/1000, 0.3)
53
54 algo := NewModifiedGenetic(pointFactory, 400, 5, evaluatorFactory, mutator)
55
56 real := func() {
57 for i := 0; i < 3000; i++ {
58 algo.Step()
59 }
60 }
61 real()
62}

Callers

nothing calls this directly

Calls 7

SeedFunction · 0.92
NewParallelFunction · 0.92
TrianglesImageFunctionsFunction · 0.92
NewGaussianMethodFunction · 0.92
NewModifiedGeneticFunction · 0.85
GenerateMethod · 0.65
StepMethod · 0.65

Tested by

no test coverage detected