forked from dfinity/canister-profiling
-
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.
[DMS-72] Implement benchmarks for PersistentOrderedMap
This is just an experiment and isn't suitable for merging to the upstream in the current state. Modifications in collections/ folder compare PersistentOrderedMap with RBTree. Second test show performance of functions from PersistentOrderedMap, that have no analogue in RBTree module.
- Loading branch information
1 parent
e87dd0d
commit 643266c
Showing
6 changed files
with
138 additions
and
55 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 |
---|---|---|
|
@@ -9,7 +9,7 @@ motoko: | |
rust: | ||
$(call build,rust) | ||
|
||
build: motoko rust | ||
build: motoko # rust | ||
|
||
perf: | ||
$(call perf,collections,perf.sh) |
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,58 @@ | ||
import Map "mo:base/PersistentOrderedMap"; | ||
import Nat64 "mo:base/Nat64"; | ||
import Nat32 "mo:base/Nat32"; | ||
import Iter "mo:base/Iter"; | ||
import Option "mo:base/Option"; | ||
import Random "random"; | ||
import Profiling "../../../utils/motoko/Profiling"; | ||
|
||
actor { | ||
stable let profiling = Profiling.init(); | ||
|
||
let mapOps = Map.MapOps<Nat64>(Nat64.compare); | ||
stable var rbMap = Map.empty<Nat64, Nat64>(); | ||
let rand = Random.new(null, 42); | ||
|
||
public func generate(size: Nat32) : async () { | ||
let rand = Random.new(?size, 1); | ||
let iter = Iter.map<Nat64, (Nat64, Nat64)>(rand, func x = (x, x)); | ||
rbMap := mapOps.fromIter(iter); | ||
}; | ||
public query func get_mem() : async (Nat,Nat,Nat) { | ||
Random.get_memory() | ||
}; | ||
public func batch_get(n : Nat) : async () { | ||
for (_ in Iter.range(1, n)) { | ||
ignore mapOps.get(rbMap, Option.get<Nat64>(rand.next(), 0)); | ||
} | ||
}; | ||
public func batch_put(n : Nat) : async () { | ||
for (_ in Iter.range(1, n)) { | ||
let k = Option.get<Nat64>(rand.next(), 0); | ||
rbMap := mapOps.put(rbMap, k, k); | ||
} | ||
}; | ||
public func batch_remove(n : Nat) : async () { | ||
let rand = Random.new(null, 1); | ||
for (_ in Iter.range(1, n)) { | ||
rbMap := mapOps.delete(rbMap, Option.get<Nat64>(rand.next(), 0)); | ||
} | ||
}; | ||
public func foldLeft() : async () { | ||
ignore Map.foldLeft<Nat64, Nat64, Nat64>(rbMap, 0, func (x, y, acc) {x + y + acc}); | ||
}; | ||
public func foldRight() : async () { | ||
ignore Map.foldRight<Nat64, Nat64, Nat64>(rbMap, 0, func (x, y, acc) {x + y + acc}); | ||
}; | ||
public func mapfilter() : async () { | ||
ignore mapOps.mapFilter<Nat64, Nat64>(rbMap, func (key, value) { | ||
switch (key % 2) { | ||
case 1 { null }; | ||
case _ { ?value } | ||
}; | ||
}) | ||
}; | ||
public func map() : async () { | ||
ignore Map.map<Nat64, Nat64, Nat64>(rbMap, func (key, value) {key + value}) | ||
}; | ||
} |
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