From df700de1fd97b232b3aab02cd3d87b4a320e358b Mon Sep 17 00:00:00 2001 From: Timo Hanke Date: Sun, 25 Jan 2026 19:11:38 +0100 Subject: [PATCH 1/6] Make bench-canister use a better Bench type The bench-canister previously expected a type for the Bench passed in by the user that was too narrow. The expected type included public setter functions in Bench. Therefore it was making an assumption about implementation details of Bench on the user's side. That was unnecessary and restrictive. This commit changes the expected to a suitable supertype which only expects the getter functions that are actually used by the bench-canister. Plus it also expects the currently still unused getVersion getter, but which is likely to be used in the future. bench-canister no longer imports the `bench` package. This makes sense because the purpose the `bench` package is as a helper to the user to write Benches. The only duplicated code between bench-canister and the `bench` package is the BenchSchema type. Still, this duplication makes sense because bench-canister defines what it needs and the package re-implements the type on the user side for convenience to the user. --- cli/commands/bench/bench-canister.mo | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cli/commands/bench/bench-canister.mo b/cli/commands/bench/bench-canister.mo index 5a7fa6b7..6f34f687 100644 --- a/cli/commands/bench/bench-canister.mo +++ b/cli/commands/bench/bench-canister.mo @@ -5,11 +5,23 @@ import InternetComputer "mo:core/InternetComputer"; import Int64 "mo:core/Int64"; import Region "mo:core/Region"; import Prim "mo:prim"; -import Bench "mo:bench"; import UserBench "./user-bench"; // file path will be replaced with the *.bench.mo file path persistent actor class () { + type BenchSchema = { + name : Text; + description : Text; + rows : [Text]; + cols : [Text]; + }; + + type Bench = { + getVersion : () -> Nat; + getSchema : () -> BenchSchema; + runCell : (Nat, Nat) -> (); + }; + type BenchResult = { instructions : Int; rts_mutator_instructions : Int; @@ -23,16 +35,16 @@ persistent actor class () { rts_reclaimed : Int; }; - transient var benchOpt : ?Bench.Bench = null; + transient var benchOpt : ?Bench = null; - public func init() : async Bench.BenchSchema { + public func init() : async BenchSchema { let bench = UserBench.init(); benchOpt := ?bench; ignore Region.grow(Region.new(), 1); bench.getSchema(); }; - public query func getSchema() : async Bench.BenchSchema { + public query func getSchema() : async BenchSchema { let ?bench = benchOpt else Runtime.trap("bench not initialized"); bench.getSchema(); }; From adf5f40777707580c8969ddadf8b17e3ffae2b7a Mon Sep 17 00:00:00 2001 From: Timo Hanke Date: Sun, 25 Jan 2026 19:31:07 +0100 Subject: [PATCH 2/6] Use Prim.rts_stable_memory_size() in bench-canister --- cli/commands/bench/bench-canister.mo | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/commands/bench/bench-canister.mo b/cli/commands/bench/bench-canister.mo index 6f34f687..32b126c9 100644 --- a/cli/commands/bench/bench-canister.mo +++ b/cli/commands/bench/bench-canister.mo @@ -2,7 +2,6 @@ import Nat64 "mo:core/Nat64"; import Nat "mo:core/Nat"; import Runtime "mo:core/Runtime"; import InternetComputer "mo:core/InternetComputer"; -import Int64 "mo:core/Int64"; import Region "mo:core/Region"; import Prim "mo:prim"; @@ -53,7 +52,7 @@ persistent actor class () { { instructions = 0; rts_heap_size = Prim.rts_heap_size(); - stable_memory_size = Int64.toInt(Int64.fromNat64(Prim.stableMemorySize())) * 65536; + stable_memory_size = Prim.rts_stable_memory_size() * 65536; rts_stable_memory_size = Prim.rts_stable_memory_size(); rts_logical_stable_memory_size = Prim.rts_logical_stable_memory_size(); rts_memory_size = Prim.rts_memory_size(); From 0d932e2b51c9962f0c5d93dc1de4a1b14208c263 Mon Sep 17 00:00:00 2001 From: Timo Hanke Date: Sun, 25 Jan 2026 20:00:09 +0100 Subject: [PATCH 3/6] Add example bench based on prng to illustrate new flexibility --- bench/prng.bench.mo | 45 +++++++++++++++++++++++++++++++++++++++++++++ mops.toml | 1 + 2 files changed, 46 insertions(+) create mode 100644 bench/prng.bench.mo diff --git a/bench/prng.bench.mo b/bench/prng.bench.mo new file mode 100644 index 00000000..1f4469ec --- /dev/null +++ b/bench/prng.bench.mo @@ -0,0 +1,45 @@ +import Prng "mo:prng"; + +module { + type Schema = { + name : Text; + description : Text; + rows : [Text]; + cols : [Text]; + }; + + class BenchV1(schema : Schema, run : (Nat, Nat) -> ()) { + public func getVersion() : Nat = 1; + public func getSchema() : Schema = schema; + public let runCell = run; + }; + + public func init() : BenchV1 { + let schema : Schema = { + name = "Prng"; + description = "Benchmark N `next` calls for different PRNGs"; + rows = ["Seiran128", "SFC64", "SFC32"]; + cols = ["10", "100", "1000", "10000"]; + }; + + let methods : [{ next : () -> Any }] = [ + Prng.Seiran128(), + Prng.SFC64a(), + Prng.SFC32a(), + ]; + + let ns : [Nat16] = [10, 100, 1000, 10000]; + + func run(ri : Nat, ci : Nat) { + let n = ns[ci]; + let next = methods[ri].next; + var i : Nat16 = 0; + while (i < n) { + ignore next(); + i +%= 1; + }; + }; + + BenchV1(schema, run); + }; +}; diff --git a/mops.toml b/mops.toml index b9f5c1cb..dae345e8 100644 --- a/mops.toml +++ b/mops.toml @@ -15,6 +15,7 @@ telegram-bot = "0.1.1" test = "2.1.1" fuzz = "1.0.0" bench = "1.0.0" +prng = "0.0.8" [toolchain] moc = "0.14.14" From ecd1dbc0b814e92a61a2961e1643b6a99e2b2db1 Mon Sep 17 00:00:00 2001 From: Timo Hanke Date: Mon, 26 Jan 2026 16:21:04 +0100 Subject: [PATCH 4/6] Fix formatting --- bench/prng.bench.mo | 2 +- cli/commands/bench/bench-canister.mo | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bench/prng.bench.mo b/bench/prng.bench.mo index 1f4469ec..18f8663e 100644 --- a/bench/prng.bench.mo +++ b/bench/prng.bench.mo @@ -39,7 +39,7 @@ module { i +%= 1; }; }; - + BenchV1(schema, run); }; }; diff --git a/cli/commands/bench/bench-canister.mo b/cli/commands/bench/bench-canister.mo index 32b126c9..f7348ac7 100644 --- a/cli/commands/bench/bench-canister.mo +++ b/cli/commands/bench/bench-canister.mo @@ -9,11 +9,11 @@ import UserBench "./user-bench"; // file path will be replaced with the *.bench. persistent actor class () { type BenchSchema = { - name : Text; - description : Text; - rows : [Text]; - cols : [Text]; - }; + name : Text; + description : Text; + rows : [Text]; + cols : [Text]; + }; type Bench = { getVersion : () -> Nat; From 566a084b58f9ba4788ba8f09630d5c419f71c03c Mon Sep 17 00:00:00 2001 From: Timo Hanke Date: Mon, 26 Jan 2026 16:27:42 +0100 Subject: [PATCH 5/6] Update mops.lock --- mops.lock | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/mops.lock b/mops.lock index 1294c685..d20088b9 100644 --- a/mops.lock +++ b/mops.lock @@ -1,6 +1,38 @@ { - "version": 2, - "mopsTomlDepsHash": "722dc0bee276245351407defa34eb1cd2f96334559d4736d892f8871144cfeb1", + "version": 3, + "mopsTomlDepsHash": "5de8f0a8a095def1d77a4d49f261b1bef9072a7352225e70d7317047d948baff", + "deps": { + "base": "0.14.14", + "time-consts": "1.0.1", + "map": "9.0.1", + "ic": "3.2.0", + "backup": "3.0.0", + "linked-list": "0.1.0", + "http-types": "1.0.1", + "motoko-datetime": "https://github.com/ByronBecker/motoko-datetime#v0.1.1@bda6139ec56d36731326727ae28510f1e1843f27", + "memory-region": "0.1.1", + "stableheapbtreemap": "1.3.0", + "matchers": "https://github.com/kritzcreek/motoko-matchers#v1.3.0", + "fuzz": "1.0.0", + "sha2": "0.1.0", + "vector": "0.4.0", + "datetime": "1.0.0", + "core": "0.6.0", + "xtended-text": "2.0.0", + "xtended-numbers": "2.0.0", + "buffer": "0.0.1", + "principal-ext": "0.1.0", + "telegram-bot": "0.1.1", + "serde": "3.3.2", + "itertools": "0.2.2", + "candid": "2.0.0", + "cbor": "4.0.0", + "byte-utils": "0.1.1", + "base@0.7.3": "0.7.3", + "test": "2.1.1", + "bench": "1.0.0", + "prng": "0.0.8" + }, "hashes": { "base@0.14.14": { "base@0.14.14/NOTICE": "3960a8d25fa5fc909325817b08b36c1146970930ca15b6352f8ea6db803cab47", @@ -671,6 +703,13 @@ "bench@1.0.0/LICENSE": "3d081f9b4a5e05c2e02a370bbfac792c81125b4efe1404f79a39359e2b923c63", "bench@1.0.0/mops.toml": "f423260f1716f4329713dfbf66343867e749e28646d29a065fac9ecd34e0ba04", "bench@1.0.0/src/lib.mo": "1dc6d4709abe393eb7a8496da873028deab9cac11e6c1464ffbde2f2d5151c5b" + }, + "prng@0.0.8": { + "prng@0.0.8/NOTICE": "71e037856ba594c2b26f5d97a1f77a907ab2013af8cbb124857ca8b53022f83f", + "prng@0.0.8/src/lib.mo": "97d00684d337fcf432d3dd0982e2a427dd54d21b931246a9c2663580e9fc46b2", + "prng@0.0.8/README.md": "90b9faa44528ca14916a5d756c187eff26d5ed61e0ca1f22d060fb51a3492a52", + "prng@0.0.8/LICENSE": "96c1cc0e3cca2329be9b477518e5c430a4fe51572b3cbcdb8a1036e06ee30855", + "prng@0.0.8/mops.toml": "19d90a2cce697c969e042d0b03d42660bf854eae930b627c678a1920ad100126" } } } \ No newline at end of file From 2d0fc6a7b9c3f2d4191f2bfe48ff2db6e46890ec Mon Sep 17 00:00:00 2001 From: Timo Hanke Date: Mon, 26 Jan 2026 18:20:54 +0100 Subject: [PATCH 6/6] Revert mops.lock to version 2 --- mops.lock | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/mops.lock b/mops.lock index d20088b9..c99eba9d 100644 --- a/mops.lock +++ b/mops.lock @@ -1,38 +1,6 @@ { - "version": 3, + "version": 2, "mopsTomlDepsHash": "5de8f0a8a095def1d77a4d49f261b1bef9072a7352225e70d7317047d948baff", - "deps": { - "base": "0.14.14", - "time-consts": "1.0.1", - "map": "9.0.1", - "ic": "3.2.0", - "backup": "3.0.0", - "linked-list": "0.1.0", - "http-types": "1.0.1", - "motoko-datetime": "https://github.com/ByronBecker/motoko-datetime#v0.1.1@bda6139ec56d36731326727ae28510f1e1843f27", - "memory-region": "0.1.1", - "stableheapbtreemap": "1.3.0", - "matchers": "https://github.com/kritzcreek/motoko-matchers#v1.3.0", - "fuzz": "1.0.0", - "sha2": "0.1.0", - "vector": "0.4.0", - "datetime": "1.0.0", - "core": "0.6.0", - "xtended-text": "2.0.0", - "xtended-numbers": "2.0.0", - "buffer": "0.0.1", - "principal-ext": "0.1.0", - "telegram-bot": "0.1.1", - "serde": "3.3.2", - "itertools": "0.2.2", - "candid": "2.0.0", - "cbor": "4.0.0", - "byte-utils": "0.1.1", - "base@0.7.3": "0.7.3", - "test": "2.1.1", - "bench": "1.0.0", - "prng": "0.0.8" - }, "hashes": { "base@0.14.14": { "base@0.14.14/NOTICE": "3960a8d25fa5fc909325817b08b36c1146970930ca15b6352f8ea6db803cab47", @@ -712,4 +680,4 @@ "prng@0.0.8/mops.toml": "19d90a2cce697c969e042d0b03d42660bf854eae930b627c678a1920ad100126" } } -} \ No newline at end of file +}