diff --git a/apps/tests/performance/performance_test.go b/apps/tests/performance/performance_test.go index 66050b72..4c4c559d 100644 --- a/apps/tests/performance/performance_test.go +++ b/apps/tests/performance/performance_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "math/rand" - "os" "testing" "time" @@ -17,7 +16,6 @@ import ( "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/fake" "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/accesstokens" "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority" - "github.com/montanaflynn/stats" ) func fakeClient() (base.Client, error) { @@ -67,62 +65,6 @@ func populateCache(users int, tokens int, authParams authority.AuthParams, clien } } } -func calculateStats(users, tokens int, duration []float64) { - - fmt.Printf("No of users: %d, No of tokens per user: %d \n", users, tokens) - - mean, err := stats.Mean(duration) - if err != nil { - panic(err) - } - meanTime := mean / float64(time.Microsecond) - fmt.Println("Mean") - fmt.Println(meanTime) - - median, err := stats.Median(duration) - medianTime := median / float64(time.Microsecond) - if err != nil { - panic(err) - } - fmt.Println("Median") - fmt.Println(medianTime) - - stdDev, err := stats.StandardDeviation(duration) - stdDevTime := stdDev / float64(time.Microsecond) - if err != nil { - panic(err) - } - fmt.Println("Standard Deviation") - fmt.Println(stdDevTime) - - min, err := stats.Min(duration) - minTime := min / float64(time.Microsecond) - if err != nil { - panic(err) - } - fmt.Println("Min Time") - fmt.Println(minTime) - - max, err := stats.Max(duration) - maxTime := max / float64(time.Microsecond) - if err != nil { - panic(err) - } - fmt.Println("Max Time") - fmt.Println(maxTime) - -} - -func benchMarkObo(users int, tokens int, client base.Client) { - var duration []float64 - for start := time.Now(); time.Since(start) < time.Minute*1; { - s := time.Now() - queryCache(users, tokens, client) - e := time.Now() - duration = append(duration, float64(e.Sub(s))) - } - calculateStats(users, tokens, duration) -} func queryCache(users int, tokens int, client base.Client) { userAssertion := fmt.Sprintf("fake_access_token%d", rand.Intn(users)) @@ -137,28 +79,30 @@ func queryCache(users int, tokens int, client base.Client) { panic(err) } } -func TestOnBehalfOfCacheTests(t *testing.T) { - if os.Getenv("CI") != "" { - t.Skip("Skipping testing in CI environment") - } - tests := []struct { - Users int - Tokens int + +func BenchmarkQueryCache(b *testing.B) { + benchmarks := []struct { + users, tokens int }{ {1, 10000}, {1, 100000}, + {10, 10000}, {100, 10000}, - {1000, 10000}, + {1000, 1000}, {10000, 100}, } - - for _, test := range tests { - client, err := fakeClient() - if err != nil { - panic(err) - } - authParams := client.AuthParams - populateCache(test.Users, test.Tokens, authParams, client) - benchMarkObo(test.Users, test.Tokens, client) + for _, bm := range benchmarks { + b.Run(fmt.Sprintf("%d users %d tokens", bm.users, bm.tokens), func(b *testing.B) { + client, err := fakeClient() + if err != nil { + b.Fatal(err) + } + authParams := client.AuthParams + populateCache(bm.users, bm.tokens, authParams, client) + b.ResetTimer() + for i := 0; i < b.N; i++ { + queryCache(bm.users, bm.tokens, client) + } + }) } } diff --git a/go.mod b/go.mod index 85e769a5..846ffdec 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/golang-jwt/jwt/v5 v5.0.0 github.com/google/uuid v1.3.0 github.com/kylelemons/godebug v1.1.0 - github.com/montanaflynn/stats v0.7.0 ) require golang.org/x/sys v0.5.0 // indirect diff --git a/go.sum b/go.sum index 7db57ffd..7a033103 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,6 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/montanaflynn/stats v0.7.0 h1:r3y12KyNxj/Sb/iOE46ws+3mS1+MZca1wlHQFPsY/JU= -github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=