diff --git a/model/fingerprinting.go b/model/fingerprinting.go index cdd0a6bbb4..e7f95dbc43 100644 --- a/model/fingerprinting.go +++ b/model/fingerprinting.go @@ -152,7 +152,37 @@ func (f fingerprint) LastCharacterOfLastLabelValue() string { } func (f fingerprint) Less(o Fingerprint) bool { - return f.String() < o.String() + // BUG(julius): Deprecate Fingerprint interface and clean this up. + fp := o.(fingerprint) + + if f.hash < fp.hash { + return true + } + if f.hash > fp.hash { + return false + } + + if f.firstCharacterOfFirstLabelName < fp.firstCharacterOfFirstLabelName { + return true + } + if f.firstCharacterOfFirstLabelName > fp.firstCharacterOfFirstLabelName { + return false + } + + if f.labelMatterLength < fp.labelMatterLength { + return true + } + if f.labelMatterLength > fp.labelMatterLength { + return false + } + + if f.lastCharacterOfLastLabelValue < fp.lastCharacterOfLastLabelValue { + return true + } + if f.lastCharacterOfLastLabelValue > fp.lastCharacterOfLastLabelValue { + return false + } + return false } func (f fingerprint) Equal(o Fingerprint) (equal bool) { diff --git a/model/fingerprinting_test.go b/model/fingerprinting_test.go index e2b2dab6c6..89069b3618 100644 --- a/model/fingerprinting_test.go +++ b/model/fingerprinting_test.go @@ -14,6 +14,7 @@ package model import ( + "runtime" "testing" ) @@ -66,3 +67,38 @@ func TestFingerprintComparison(t *testing.T) { } } } + +func BenchmarkFingerprinting(b *testing.B) { + b.StopTimer() + fps := []fingerprint{ + { + hash: 0, + firstCharacterOfFirstLabelName: "a", + labelMatterLength: 2, + lastCharacterOfLastLabelValue: "z", + }, + { + hash: 0, + firstCharacterOfFirstLabelName: "a", + labelMatterLength: 2, + lastCharacterOfLastLabelValue: "z", + }, + } + for i := 0; i < 10; i++ { + fps[0].Less(fps[1]) + } + b.Logf("N: %v", b.N) + b.StartTimer() + + var pre runtime.MemStats + runtime.ReadMemStats(&pre) + + for i := 0; i < b.N; i++ { + fps[0].Less(fps[1]) + } + + var post runtime.MemStats + runtime.ReadMemStats(&post) + + b.Logf("allocs: %d items: ", post.TotalAlloc-pre.TotalAlloc) +}