generated from xmidt-org/.go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from xmidt-org/feature/benchmarks
Feature/benchmarks
- Loading branch information
Showing
5 changed files
with
120 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-FileCopyrightText: 2025 Comcast Cable Communications Management, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package consistent | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"testing" | ||
) | ||
|
||
const ( | ||
// objectSeed is the random number seed we use to create objects to hash | ||
objectSeed int64 = 7245298734452934458 | ||
|
||
// objectCount is the number of random objects we generate for hash inputs | ||
objectCount int = 1000 | ||
|
||
// serviceCount is the number of random service names to generate for hashes | ||
serviceCount int = 100 | ||
) | ||
|
||
// hashObjects contains a standard set of random objects to hash to services. | ||
var hashObjects [objectCount][16]byte | ||
|
||
// services contains a number of service names to use in tests and benchmarks. | ||
var services [serviceCount]string | ||
|
||
func TestMain(m *testing.M) { | ||
random := rand.New( | ||
rand.NewSource(objectSeed), | ||
) | ||
|
||
for i := range len(hashObjects) { | ||
random.Read(hashObjects[i][:]) | ||
} | ||
|
||
for i := range len(services) { | ||
services[i] = fmt.Sprintf("service-%d.example.net", i) | ||
} | ||
|
||
m.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-FileCopyrightText: 2025 Comcast Cable Communications Management, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package consistent | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/billhathaway/consistentHash" | ||
) | ||
|
||
var benchmarkVnodes = []int{50, 100, 200} | ||
|
||
func BenchmarkRingCreation(b *testing.B) { | ||
for _, vnodes := range benchmarkVnodes { | ||
b.Run( | ||
fmt.Sprintf("vnodes-%d", vnodes), | ||
func(b *testing.B) { | ||
for range b.N { | ||
Strings(services[:]...).VNodes(vnodes).Build() | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
|
||
func BenchmarkConsistentHashCreation(b *testing.B) { | ||
for _, vnodes := range benchmarkVnodes { | ||
b.Run( | ||
fmt.Sprintf("vnodes-%d", vnodes), | ||
func(b *testing.B) { | ||
for range b.N { | ||
ch := consistentHash.New() | ||
ch.SetVnodeCount(vnodes) | ||
for _, service := range services { | ||
ch.Add(service) | ||
} | ||
} | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters