-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sai/merged sets #535
Closed
Closed
Sai/merged sets #535
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b3c0205
set as linked list
saiskee 3c33ba0
update
saiskee c4a56ca
update sets
saiskee 774f406
goimports
saiskee 0996c13
update
saiskee 55f8fcc
update
saiskee 90c9218
update
saiskee 078e52a
initial
saiskee f88c63a
update
saiskee 5af7308
update
saiskee 2e5bc76
update
saiskee c20211d
update
saiskee 720c1f4
update
saiskee 53ba10f
previous commit reverted the slice sets impelemtantion
saiskee 1884e63
Merge remote-tracking branch 'origin/main' into sai/merged-sets
saiskee 100e313
update
saiskee 7489cd7
update
saiskee 6dc774d
update
saiskee dfcaae0
update
saiskee 7c30649
update
saiskee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package sets | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
v1 "github.com/solo-io/skv2/pkg/api/core.skv2.solo.io/v1" | ||
"github.com/solo-io/skv2/pkg/ezkube" | ||
) | ||
|
||
// Define a global variable to prevent compiler optimizations | ||
var result interface{} | ||
|
||
var scale = 10000 | ||
|
||
// func Benchmark(b *testing.B) { | ||
// b.Run("Resources_Insert", BenchmarkResources_Insert) | ||
// b.Run("Resources_Find", BenchmarkResources_Find) | ||
// // b.Run("Resources_Delete", BenchmarkResources_Delete) | ||
// b.Run("Resources_List", BenchmarkResources_List) | ||
// b.Run("Resources_UnsortedList", BenchmarkResources_UnsortedList) | ||
// } | ||
|
||
func BenchmarkResources_Insert(b *testing.B) { | ||
var r Resources | ||
for i := 0; i < b.N; i++ { | ||
r = newResources() // Assume newResources is corrected to initialize correctly | ||
for j := 0; j < scale; j++ { | ||
resource := &v1.ObjectRef{Namespace: "namespace", Name: "name" + fmt.Sprint(j)} | ||
r.Insert(resource) | ||
} | ||
} | ||
// Store the result to a package level variable | ||
// so the compiler cannot eliminate the Benchmark itself. | ||
result = r | ||
} | ||
|
||
func BenchmarkResources_Find(b *testing.B) { | ||
r := newResources() | ||
for j := 0; j < scale; j++ { | ||
resource := &v1.ObjectRef{Namespace: "namespace", Name: "name" + fmt.Sprint(j)} | ||
r.Insert(resource) | ||
} | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, _ = r.Find(&v1.TypedObjectRef{}, &v1.ObjectRef{Namespace: "namespace", Name: "name500"}) | ||
} | ||
} | ||
|
||
func BenchmarkResources_Delete(b *testing.B) { | ||
var r Resources | ||
for i := 0; i < b.N; i++ { | ||
r = newResources() | ||
for j := 0; j < scale; j++ { | ||
resource := &v1.ObjectRef{Namespace: "namespace", Name: "name" + fmt.Sprint(j)} | ||
r.Insert(resource) | ||
} | ||
b.ResetTimer() | ||
for j := 0; j < scale; j++ { | ||
r.Delete(&v1.ObjectRef{Namespace: "namespace", Name: "name" + fmt.Sprint(j)}) | ||
} | ||
b.StopTimer() | ||
} | ||
result = r | ||
} | ||
|
||
func BenchmarkResources_List(b *testing.B) { | ||
r := newResources() | ||
for j := 0; j < scale; j++ { | ||
resource := &v1.ObjectRef{Namespace: "namespace", Name: "name" + fmt.Sprint(j)} | ||
r.Insert(resource) | ||
} | ||
|
||
b.ResetTimer() | ||
var res []ezkube.ResourceId | ||
for i := 0; i < b.N; i++ { | ||
res = r.List() | ||
} | ||
// Store the result to prevent the compiler from optimizing the loop away. | ||
result = res | ||
} | ||
|
||
func BenchmarkResources_UnsortedList(b *testing.B) { | ||
r := newResources() | ||
for j := 0; j < scale; j++ { | ||
resource := &v1.ObjectRef{Namespace: "namespace", Name: "name" + fmt.Sprint(j)} | ||
r.Insert(resource) | ||
} | ||
|
||
b.ResetTimer() | ||
var res []ezkube.ResourceId | ||
for i := 0; i < b.N; i++ { | ||
res = r.UnsortedList() | ||
} | ||
// Store the result to prevent the compiler from optimizing the loop away. | ||
result = res | ||
} | ||
|
||
// func BenchmarkResources_Delta(b *testing.B) { | ||
// // Define the scale for the number of resources in each set. | ||
// const scale = 1000 | ||
|
||
// // Create and populate the original set with resources. | ||
// originalSet := newResources() | ||
// for i := 0; i < scale; i++ { | ||
// resource := &v1.ObjectRef{Namespace: "namespace", Name: "originalName" + fmt.Sprint(i)} | ||
// originalSet.Insert(resource) | ||
// } | ||
|
||
// // Create and populate a new set with some overlapping and some unique resources. | ||
// newSet := newResources() | ||
// for i := scale / 2; i < scale+(scale/2); i++ { | ||
// resource := &v1.ObjectRef{Namespace: "namespace", Name: "newName" + fmt.Sprint(i)} | ||
// newSet.Insert(resource) | ||
// } | ||
|
||
// b.ResetTimer() // Start timing the benchmark loop. | ||
// for i := 0; i < b.N; i++ { | ||
// _ = originalSet.Delta(newSet) | ||
// } | ||
// } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main effective change, clone now produces a merged set, which is a a list of sets which is iterated through on methods like
Find
orList