Skip to content

Conversation

@JungukCho
Copy link
Contributor

Reason for Change:

To avoid using heavy deepEqual to compare label and be consistent with other controller codes.

Issue Fixed:

Requirements:

Notes:
Test two functions and their results.

package testing

import (
	"reflect"
	"testing"

	k8slabels "k8s.io/apimachinery/pkg/labels"
)

func BenchmarkLabelEqual(b *testing.B) {
	labelA := map[string]string{
		"project": "myproject",
		"role":    "frontend",
	}
	labelB := map[string]string{
		"project": "myproject",
		"role":    "frontend",
	}
	for i := 0; i < b.N; i++ {
		k8slabels.Equals(labelA, labelB)
	}
}

func BenchmarkLabelDeepEqual(b *testing.B) {
	labelA := map[string]string{
		"project": "myproject",
		"role":    "frontend",
	}
	labelB := map[string]string{
		"project": "myproject",
		"role":    "frontend",
	}
	for i := 0; i < b.N; i++ {
		reflect.DeepEqual(labelA, labelB)
	}
}
Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -bench ^BenchmarkLabelEqual$ benchmarking.com

goos: linux
goarch: amd64
pkg: benchmarking.com
cpu: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
BenchmarkLabelEqual-8   	18292081	        70.08 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	benchmarking.com	1.360s


Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -bench ^BenchmarkLabelDeepEqual$ benchmarking.com
goos: linux
goarch: amd64
pkg: benchmarking.com
cpu: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
BenchmarkLabelDeepEqual-8   	 1522663	      1082 ns/op	     240 B/op	       8 allocs/op
PASS
ok  	benchmarking.com	3.529s

@JungukCho JungukCho added the npm Related to NPM. label Nov 16, 2021
Copy link
Contributor

@vakalapa vakalapa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm,

Copy link
Collaborator

@rbtr rbtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

@JungukCho
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@JungukCho
Copy link
Contributor Author

😍

Thank you for cool reference for equal function

@JungukCho
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@JungukCho JungukCho merged commit cd43806 into Azure:master Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

npm Related to NPM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants