diff --git a/Makefile b/Makefile index 9223b77..ca98b80 100644 --- a/Makefile +++ b/Makefile @@ -4,5 +4,8 @@ example: test: go test -race -count=1 --parallel 8 ./... +bench: + go run blob/bench/bench.go + get_coverage_pic: gopherbadger -md="README.md,coverage.out" diff --git a/blob/bench/bench.go b/blob/bench/bench.go index 04e04d0..34488b8 100644 --- a/blob/bench/bench.go +++ b/blob/bench/bench.go @@ -6,8 +6,9 @@ import ( "sync" "time" - "github.com/koss-null/funcfrog/pkg/ff" "github.com/pkg/profile" + + "github.com/koss-null/funcfrog/pkg/ff" ) type User struct { @@ -33,6 +34,7 @@ func GetUserID(u *User) string { } func main() { + const iters = 5 makeUsers(1) defer profile.Start().Stop() // n == number of users @@ -45,11 +47,11 @@ func main() { 10_000_000, } { users := makeUsers(n) - for i := 0; i < 3; i++ { - _ = ff.Map(users, GetUserID).Parallel(4).Do() + for i := 0; i < iters; i++ { + _ = ff.Map(users, GetUserID).Parallel(8).Do() } } - fmt.Println("done in", time.Since(start)) + fmt.Println("FuncFrog done in", time.Since(start)) start = time.Now() for _, n := range []int{ @@ -60,7 +62,7 @@ func main() { 10_000_000, } { users := makeUsers(n) - for i := 0; i < 3; i++ { + for i := 0; i < iters; i++ { res := make([]string, 0, len(users)) for j := range users { res = append(res, GetUserID(users[j])) @@ -68,7 +70,7 @@ func main() { _ = res } } - fmt.Println("done in", time.Since(start)) + fmt.Println("for loop done in", time.Since(start)) } var ( diff --git a/go.mod b/go.mod index 58e5eaa..0d13d43 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,15 @@ module github.com/koss-null/funcfrog go 1.18 require ( + github.com/pkg/profile v1.7.0 github.com/stretchr/testify v1.8.0 golang.org/x/exp v0.0.0-20231006140011-7918f672742d ) require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/felixge/fgprof v0.9.3 // indirect + github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 24e57d6..d25a2b3 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,16 @@ +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g= +github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw= +github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y= +github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= +github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= +github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA= +github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -10,6 +20,7 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=