From 3d00f09914d7d57dee68661fb726e4a75e0df3cf Mon Sep 17 00:00:00 2001 From: surtur Date: Thu, 16 Jun 2022 17:15:39 +0200 Subject: [PATCH] chore(go): move functions to its own file --- bench/bench.go | 35 ----------------------------------- bench/functions.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 bench/functions.go diff --git a/bench/bench.go b/bench/bench.go index a428c65..122eed5 100644 --- a/bench/bench.go +++ b/bench/bench.go @@ -3,8 +3,6 @@ package bench -import "math" - type funcParams struct { min float64 max float64 @@ -34,36 +32,3 @@ func (*funcParams) Min(self *funcParams) float64 { func (*funcParams) Max(self *funcParams) float64 { return self.max } - -// Schwefel computes a value of the Schwefel function for x. -func Schwefel(x []float64) float64 { - var res float64 - - for _, val := range x { - res += val * math.Sin(math.Sqrt(math.Abs(val))) - } - - return 418.9829*float64(len(x)) - res -} - -// DeJong1st computes the value of the 1st De Jong function for x. -func DeJong1st(x []float64) float64 { - var res float64 - - for _, val := range x { - res += math.Floor(val) - } - - return res -} - -// DeJong2nd computes the value of the 2nd De Jong function for x. -func DeJong2nd(x []float64) float64 { - var res float64 - - for _, val := range x { - res += math.Pow(val, 2) - } - - return res -} diff --git a/bench/functions.go b/bench/functions.go new file mode 100644 index 0000000..1638132 --- /dev/null +++ b/bench/functions.go @@ -0,0 +1,39 @@ +// Copyright 2022 wanderer +// SPDX-License-Identifier: GPL-3.0-or-later + +package bench + +import "math" + +// Schwefel computes a value of the Schwefel function for x. +func Schwefel(x []float64) float64 { + var res float64 + + for _, val := range x { + res += val * math.Sin(math.Sqrt(math.Abs(val))) + } + + return 418.9829*float64(len(x)) - res +} + +// DeJong1st computes the value of the 1st De Jong function for x. +func DeJong1st(x []float64) float64 { + var res float64 + + for _, val := range x { + res += math.Floor(val) + } + + return res +} + +// DeJong2nd computes the value of the 2nd De Jong function for x. +func DeJong2nd(x []float64) float64 { + var res float64 + + for _, val := range x { + res += math.Pow(val, 2) + } + + return res +}