-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add AVLSet implementation, unit tests and benchmarks #17
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
Open
LeoN192
wants to merge
10
commits into
Lamagraph:main
Choose a base branch
from
LeoN192:avlset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ae9028e
feat: add AVLSet implementation, unit tests and benchmarks
LeoN192 04e6a98
feat: refactor AVLSet architecture and add property tests
LeoN192 c8bead9
format files
LeoN192 6a3bfb6
Refactor to AVLSet: remove Node module, simplify rotations via patter…
LeoN192 593a5c8
refactor: replace exceptions with Result type for error handling
LeoN192 bcaceae
format files
LeoN192 f706105
add info to README and improve benchmarks
LeoN192 7916f50
formatted
LeoN192 8eb71a7
add benchmark results to README
LeoN192 e52c2fd
make benchmark results in README more detailed
LeoN192 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
This file contains hidden or 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,219 @@ | ||
| namespace QuadTree.Benchmarks.AVLSet | ||
|
|
||
| open BenchmarkDotNet.Attributes | ||
| open BenchmarkDotNet.Configs | ||
| open QuadTree.AVLSet | ||
| open QuadTree.AVLSet.Parallel | ||
|
|
||
| [<GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)>] | ||
| [<CategoriesColumn>] | ||
| [<HtmlExporter>] | ||
| [<MemoryDiagnoser>] | ||
| type SingleOpsBenchmark() = | ||
| let rnd = System.Random(1234561) | ||
|
|
||
| [<Params(100, 10000, 100000)>] | ||
| [<DefaultValue>] | ||
| val mutable public A: int | ||
|
|
||
| [<DefaultValue>] | ||
| val mutable public rndInt: int | ||
|
|
||
| [<DefaultValue>] | ||
| val mutable public setA: AVLSet<int> | ||
|
|
||
| [<GlobalSetup>] | ||
| member self.Setup() = | ||
| self.rndInt <- rnd.Next(self.A + 1, self.A + 1000) | ||
|
|
||
| let dataA = Array.init self.A (fun _ -> rnd.Next()) | ||
|
|
||
| self.setA <- | ||
| dataA | ||
| |> Array.fold | ||
| (fun (set: AVLSet<int>) v -> | ||
| match AVLSet.add v set with | ||
| | Ok nextSet -> nextSet | ||
| | Error err -> failwithf "Benchmark setup failed: %A" err) | ||
| AVLSet.empty | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Adding")>] | ||
| member self.AddingOneElement() = AVLSet.add self.rndInt self.setA | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Deleting")>] | ||
| member self.DeletingOneElement() = AVLSet.delete self.rndInt self.setA | ||
|
|
||
|
|
||
| [<GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)>] | ||
| [<CategoriesColumn>] | ||
| [<HtmlExporter>] | ||
| [<MemoryDiagnoser>] | ||
| type SequentialSetsBenchmark() = | ||
| let rnd = System.Random(1234561) | ||
|
|
||
| [<Params(100, 10000, 100000)>] | ||
| [<DefaultValue>] | ||
| val mutable public A: int | ||
|
|
||
| [<Params(100, 10000)>] | ||
| [<DefaultValue>] | ||
| val mutable public B: int | ||
|
|
||
| [<DefaultValue>] | ||
| val mutable public setA: AVLSet<int> | ||
|
|
||
| [<DefaultValue>] | ||
| val mutable public setB: AVLSet<int> | ||
|
|
||
| [<GlobalSetup>] | ||
| member self.Setup() = | ||
| let dataA = Array.init self.A (fun _ -> rnd.Next()) | ||
|
|
||
| let dataB = Array.init self.B (fun _ -> rnd.Next()) | ||
|
|
||
| self.setA <- | ||
| dataA | ||
| |> Array.fold | ||
| (fun (set: AVLSet<int>) v -> | ||
| match AVLSet.add v set with | ||
| | Ok nextSet -> nextSet | ||
| | Error err -> failwithf "Benchmark setup failed: %A" err) | ||
| AVLSet.empty | ||
|
|
||
| self.setB <- | ||
| dataB | ||
| |> Array.fold | ||
| (fun (set: AVLSet<int>) v -> | ||
| match AVLSet.add v set with | ||
| | Ok nextSet -> nextSet | ||
| | Error err -> failwithf "Benchmark setup failed: %A" err) | ||
| AVLSet.empty | ||
|
|
||
| [<Benchmark(Baseline = true)>] | ||
| [<BenchmarkCategory("Union")>] | ||
| member self.SequentialUnion() = AVLSet.union self.setA self.setB | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Union")>] | ||
| member self.UnionViaTreeTraversal() = | ||
| AVLSet.Traversal.union self.setA self.setB | ||
|
|
||
| [<Benchmark(Baseline = true)>] | ||
| [<BenchmarkCategory("Intersection")>] | ||
| member self.SequentialIntersection() = AVLSet.intersection self.setA self.setB | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Intersection")>] | ||
| member self.IntersectionViaTreeTraversal() = | ||
| AVLSet.Traversal.intersection self.setA self.setB | ||
|
|
||
| [<Benchmark(Baseline = true)>] | ||
| [<BenchmarkCategory("Difference")>] | ||
| member self.SequentialDifference() = AVLSet.difference self.setA self.setB | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Difference")>] | ||
| member self.DifferenceViaTreeTraversal() = | ||
| AVLSet.Traversal.difference self.setA self.setB | ||
|
|
||
| [<Benchmark(Baseline = true)>] | ||
| [<BenchmarkCategory("Symmetrical Difference")>] | ||
| member self.SequentialSymmetricalDifference() = | ||
| AVLSet.symmDifference self.setA self.setB | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Symmetrical Difference")>] | ||
| member self.SymmetricalDifferenceViaTreeTraversal() = | ||
| AVLSet.Traversal.symmDifference self.setA self.setB | ||
|
|
||
|
|
||
| [<ShortRunJob>] | ||
| [<GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)>] | ||
| [<CategoriesColumn>] | ||
| [<HtmlExporter>] | ||
| [<MemoryDiagnoser>] | ||
| [<ThreadingDiagnoser>] | ||
| type ParallelSetsBenchmark() = | ||
| let rnd = System.Random(1234561) | ||
|
|
||
| [<Params(1000, 10000, 100000)>] | ||
| [<DefaultValue>] | ||
| val mutable public A: int | ||
|
|
||
| [<Params(100, 10000)>] | ||
| [<DefaultValue>] | ||
| val mutable public B: int | ||
|
|
||
| [<Params(1, 2, 4)>] | ||
| [<DefaultValue>] | ||
| val mutable public threads: int | ||
|
|
||
| [<DefaultValue>] | ||
| val mutable public setA: AVLSet<int> | ||
|
|
||
| [<DefaultValue>] | ||
| val mutable public setB: AVLSet<int> | ||
|
|
||
| [<GlobalSetup>] | ||
| member self.Setup() = | ||
| let dataA = Array.init self.A (fun _ -> rnd.Next()) | ||
|
|
||
| let dataB = Array.init self.B (fun _ -> rnd.Next()) | ||
|
|
||
| self.setA <- | ||
| dataA | ||
| |> Array.fold | ||
| (fun set v -> | ||
| match AVLSet.add v set with | ||
| | Ok s -> s | ||
| | Error e -> failwithf "%A" e) | ||
| AVLSet.empty | ||
|
|
||
| self.setB <- | ||
| dataB | ||
| |> Array.fold | ||
| (fun set v -> | ||
| match AVLSet.add v set with | ||
| | Ok s -> s | ||
| | Error e -> failwithf "%A" e) | ||
| AVLSet.empty | ||
|
|
||
|
|
||
| [<Benchmark(Baseline = true)>] | ||
| [<BenchmarkCategory("Union")>] | ||
| member self.SequentialUnion() = AVLSet.union self.setA self.setB | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Union")>] | ||
| member self.ParallelUnionWithThreads() = | ||
| ParallelAVLSet.union (Some self.threads) self.setA self.setB | ||
|
|
||
| [<Benchmark(Baseline = true)>] | ||
| [<BenchmarkCategory("Intersection")>] | ||
| member self.SequentialIntersection() = AVLSet.intersection self.setA self.setB | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Intersection")>] | ||
| member self.ParallelIntersectionWithThreads() = | ||
| ParallelAVLSet.intersection (Some self.threads) self.setA self.setB | ||
|
|
||
| [<Benchmark(Baseline = true)>] | ||
| [<BenchmarkCategory("Difference")>] | ||
| member self.SequentialDifference() = AVLSet.difference self.setA self.setB | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Difference")>] | ||
| member self.ParallelDifferenceWithThreads() = | ||
| ParallelAVLSet.difference (Some self.threads) self.setA self.setB | ||
|
|
||
| [<Benchmark(Baseline = true)>] | ||
| [<BenchmarkCategory("Symmetrical Difference")>] | ||
| member self.SequentialSymmetricalDifference() = | ||
| AVLSet.symmDifference self.setA self.setB | ||
|
|
||
| [<Benchmark>] | ||
| [<BenchmarkCategory("Symmetrical Difference")>] | ||
| member self.ParallelSymmetricalDifferenceWithThreads() = | ||
| ParallelAVLSet.symmDifference (Some self.threads) self.setA self.setB | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.