Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions bench/prng.bench.mo
Original file line number Diff line number Diff line change
@@ -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);
};
};
23 changes: 17 additions & 6 deletions cli/commands/bench/bench-canister.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@ 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";
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;
Expand All @@ -23,16 +34,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();
};
Expand All @@ -41,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();
Expand Down
11 changes: 9 additions & 2 deletions mops.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 2,
"mopsTomlDepsHash": "722dc0bee276245351407defa34eb1cd2f96334559d4736d892f8871144cfeb1",
"mopsTomlDepsHash": "5de8f0a8a095def1d77a4d49f261b1bef9072a7352225e70d7317047d948baff",
"hashes": {
"base@0.14.14": {
"base@0.14.14/NOTICE": "3960a8d25fa5fc909325817b08b36c1146970930ca15b6352f8ea6db803cab47",
Expand Down Expand Up @@ -671,6 +671,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"
}
}
}
}
1 change: 1 addition & 0 deletions mops.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading