ic-mops 0.28.1 → 0.28.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/init.ts +16 -9
- package/declarations/main/main.did +36 -0
- package/declarations/main/main.did.d.ts +28 -0
- package/declarations/main/main.did.js +32 -0
- package/dist/bench/$USER_BENCH_FILE.mo +45 -0
- package/dist/bench/bench-canister.mo +57 -0
- package/dist/commands/bench/$USER_BENCH_FILE.mo +45 -0
- package/dist/commands/bench/bench/$USER_BENCH_FILE.mo +45 -0
- package/dist/commands/bench/bench/bench-canister.mo +57 -0
- package/dist/commands/bench/bench-canister.mo +85 -0
- package/dist/commands/bench/declarations/bench/bench.did.d.ts +6 -0
- package/dist/commands/bench/declarations/bench/bench.did.js +22 -0
- package/dist/commands/bench/declarations/bench/index.d.ts +2 -0
- package/dist/commands/bench/declarations/bench/index.js +30 -0
- package/dist/commands/bench/declarations/main/index.d.ts +2 -0
- package/dist/commands/bench/declarations/main/index.js +30 -0
- package/dist/commands/bench/declarations/main/main.did.d.ts +6 -0
- package/dist/commands/bench/declarations/main/main.did.js +242 -0
- package/dist/commands/bench/declarations/storage/index.d.ts +4 -0
- package/dist/commands/bench/declarations/storage/index.js +26 -0
- package/dist/commands/bench/declarations/storage/storage.did.d.ts +6 -0
- package/dist/commands/bench/declarations/storage/storage.did.js +34 -0
- package/dist/commands/bench/user-bench.mo +14 -0
- package/dist/commands/bench.d.ts +9 -2
- package/dist/commands/bench.js +155 -71
- package/dist/commands/init.js +16 -9
- package/dist/declarations/bench/bench.did +24 -0
- package/dist/declarations/bench/bench.did.d.ts +24 -0
- package/dist/declarations/bench/bench.did.js +24 -0
- package/dist/declarations/bench/index.d.ts +50 -0
- package/dist/declarations/bench/index.js +41 -0
- package/dist/declarations/main/main.did +36 -0
- package/dist/declarations/main/main.did.d.ts +28 -0
- package/dist/declarations/main/main.did.js +32 -0
- package/dist/helpers/get-dfx-version.d.ts +1 -0
- package/dist/helpers/get-dfx-version.js +9 -0
- package/dist/helpers/get-moc-path.d.ts +1 -0
- package/dist/helpers/get-moc-path.js +11 -0
- package/dist/helpers/get-moc-version.d.ts +1 -0
- package/dist/helpers/get-moc-version.js +7 -0
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/commands/init.ts
CHANGED
|
@@ -174,15 +174,22 @@ async function applyInit({type, config, setupWorkflow, addTest, copyrightOwner}
|
|
|
174
174
|
let dfxJsonData;
|
|
175
175
|
if (existsSync(dfxJson)) {
|
|
176
176
|
let dfxJsonText = readFileSync(dfxJson).toString();
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
177
|
+
try {
|
|
178
|
+
dfxJsonData = JSON.parse(dfxJsonText);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
console.log(chalk.yellow('Failed to parse dfx.json'));
|
|
182
|
+
}
|
|
183
|
+
if (dfxJsonData) {
|
|
184
|
+
console.log('Setting packtool in dfx.json...');
|
|
185
|
+
dfxJsonData.defaults = dfxJsonData.defaults || {};
|
|
186
|
+
dfxJsonData.defaults.build = dfxJsonData.defaults.build || {};
|
|
187
|
+
if (dfxJsonData.defaults.build.packtool !== 'mops sources') {
|
|
188
|
+
dfxJsonData.defaults.build.packtool = 'mops sources';
|
|
189
|
+
let indent = dfxJsonText.match(/([ \t]+)"/)?.[1] || ' ';
|
|
190
|
+
writeFileSync(path.join(process.cwd(), 'dfx.json'), JSON.stringify(dfxJsonData, null, indent));
|
|
191
|
+
console.log(chalk.green('packtool set to "mops sources"'));
|
|
192
|
+
}
|
|
186
193
|
}
|
|
187
194
|
}
|
|
188
195
|
|
|
@@ -41,6 +41,20 @@ type TestStats =
|
|
|
41
41
|
passed: nat;
|
|
42
42
|
passedNames: vec text;
|
|
43
43
|
};
|
|
44
|
+
type StreamingToken = blob;
|
|
45
|
+
type StreamingStrategy = variant {
|
|
46
|
+
Callback:
|
|
47
|
+
record {
|
|
48
|
+
callback: StreamingCallback;
|
|
49
|
+
token: StreamingToken;
|
|
50
|
+
};};
|
|
51
|
+
type StreamingCallbackResponse =
|
|
52
|
+
record {
|
|
53
|
+
body: blob;
|
|
54
|
+
token: opt StreamingToken;
|
|
55
|
+
};
|
|
56
|
+
type StreamingCallback = func (StreamingToken) ->
|
|
57
|
+
(opt StreamingCallbackResponse) query;
|
|
44
58
|
type StorageStats =
|
|
45
59
|
record {
|
|
46
60
|
cyclesBalance: nat;
|
|
@@ -102,6 +116,22 @@ type Result =
|
|
|
102
116
|
err: Err;
|
|
103
117
|
ok;
|
|
104
118
|
};
|
|
119
|
+
type Response =
|
|
120
|
+
record {
|
|
121
|
+
body: blob;
|
|
122
|
+
headers: vec Header;
|
|
123
|
+
status_code: nat16;
|
|
124
|
+
streaming_strategy: opt StreamingStrategy;
|
|
125
|
+
upgrade: opt bool;
|
|
126
|
+
};
|
|
127
|
+
type Request =
|
|
128
|
+
record {
|
|
129
|
+
body: blob;
|
|
130
|
+
certificate_version: opt nat16;
|
|
131
|
+
headers: vec Header;
|
|
132
|
+
method: text;
|
|
133
|
+
url: text;
|
|
134
|
+
};
|
|
105
135
|
type PublishingId = text;
|
|
106
136
|
type PublishingErr = text;
|
|
107
137
|
type PageCount = nat;
|
|
@@ -232,6 +262,11 @@ type PackageChanges =
|
|
|
232
262
|
notes: text;
|
|
233
263
|
tests: TestsChanges;
|
|
234
264
|
};
|
|
265
|
+
type Header =
|
|
266
|
+
record {
|
|
267
|
+
text;
|
|
268
|
+
text;
|
|
269
|
+
};
|
|
235
270
|
type FileId = text;
|
|
236
271
|
type Err = text;
|
|
237
272
|
type DownloadsSnapshot__1 =
|
|
@@ -300,6 +335,7 @@ service : {
|
|
|
300
335
|
getTotalDownloads: () -> (nat) query;
|
|
301
336
|
getTotalPackages: () -> (nat) query;
|
|
302
337
|
getUser: (principal) -> (opt User__1) query;
|
|
338
|
+
http_request: (Request) -> (Response) query;
|
|
303
339
|
notifyInstall: (PackageName__1, PackageVersion) -> () oneway;
|
|
304
340
|
notifyInstalls: (vec record {
|
|
305
341
|
PackageName__1;
|
|
@@ -23,6 +23,7 @@ export interface DownloadsSnapshot__1 {
|
|
|
23
23
|
}
|
|
24
24
|
export type Err = string;
|
|
25
25
|
export type FileId = string;
|
|
26
|
+
export type Header = [string, string];
|
|
26
27
|
export interface PackageChanges {
|
|
27
28
|
'tests' : TestsChanges,
|
|
28
29
|
'deps' : Array<DepChange>,
|
|
@@ -142,6 +143,20 @@ export type PackageVersion = string;
|
|
|
142
143
|
export type PageCount = bigint;
|
|
143
144
|
export type PublishingErr = string;
|
|
144
145
|
export type PublishingId = string;
|
|
146
|
+
export interface Request {
|
|
147
|
+
'url' : string,
|
|
148
|
+
'method' : string,
|
|
149
|
+
'body' : Uint8Array | number[],
|
|
150
|
+
'headers' : Array<Header>,
|
|
151
|
+
'certificate_version' : [] | [number],
|
|
152
|
+
}
|
|
153
|
+
export interface Response {
|
|
154
|
+
'body' : Uint8Array | number[],
|
|
155
|
+
'headers' : Array<Header>,
|
|
156
|
+
'upgrade' : [] | [boolean],
|
|
157
|
+
'streaming_strategy' : [] | [StreamingStrategy],
|
|
158
|
+
'status_code' : number,
|
|
159
|
+
}
|
|
145
160
|
export type Result = { 'ok' : null } |
|
|
146
161
|
{ 'err' : Err };
|
|
147
162
|
export type Result_1 = { 'ok' : PublishingId } |
|
|
@@ -168,6 +183,18 @@ export interface StorageStats {
|
|
|
168
183
|
'cyclesBalance' : bigint,
|
|
169
184
|
'memorySize' : bigint,
|
|
170
185
|
}
|
|
186
|
+
export type StreamingCallback = ActorMethod<
|
|
187
|
+
[StreamingToken],
|
|
188
|
+
[] | [StreamingCallbackResponse]
|
|
189
|
+
>;
|
|
190
|
+
export interface StreamingCallbackResponse {
|
|
191
|
+
'token' : [] | [StreamingToken],
|
|
192
|
+
'body' : Uint8Array | number[],
|
|
193
|
+
}
|
|
194
|
+
export type StreamingStrategy = {
|
|
195
|
+
'Callback' : { 'token' : StreamingToken, 'callback' : StreamingCallback }
|
|
196
|
+
};
|
|
197
|
+
export type StreamingToken = Uint8Array | number[];
|
|
171
198
|
export interface TestStats { 'passedNames' : Array<string>, 'passed' : bigint }
|
|
172
199
|
export interface TestStats__1 {
|
|
173
200
|
'passedNames' : Array<string>,
|
|
@@ -246,6 +273,7 @@ export interface _SERVICE {
|
|
|
246
273
|
'getTotalDownloads' : ActorMethod<[], bigint>,
|
|
247
274
|
'getTotalPackages' : ActorMethod<[], bigint>,
|
|
248
275
|
'getUser' : ActorMethod<[Principal], [] | [User__1]>,
|
|
276
|
+
'http_request' : ActorMethod<[Request], Response>,
|
|
249
277
|
'notifyInstall' : ActorMethod<[PackageName__1, PackageVersion], undefined>,
|
|
250
278
|
'notifyInstalls' : ActorMethod<
|
|
251
279
|
[Array<[PackageName__1, PackageVersion]>],
|
|
@@ -174,6 +174,37 @@ export const idlFactory = ({ IDL }) => {
|
|
|
174
174
|
'githubVerified' : IDL.Bool,
|
|
175
175
|
'github' : IDL.Text,
|
|
176
176
|
});
|
|
177
|
+
const Header = IDL.Tuple(IDL.Text, IDL.Text);
|
|
178
|
+
const Request = IDL.Record({
|
|
179
|
+
'url' : IDL.Text,
|
|
180
|
+
'method' : IDL.Text,
|
|
181
|
+
'body' : IDL.Vec(IDL.Nat8),
|
|
182
|
+
'headers' : IDL.Vec(Header),
|
|
183
|
+
'certificate_version' : IDL.Opt(IDL.Nat16),
|
|
184
|
+
});
|
|
185
|
+
const StreamingToken = IDL.Vec(IDL.Nat8);
|
|
186
|
+
const StreamingCallbackResponse = IDL.Record({
|
|
187
|
+
'token' : IDL.Opt(StreamingToken),
|
|
188
|
+
'body' : IDL.Vec(IDL.Nat8),
|
|
189
|
+
});
|
|
190
|
+
const StreamingCallback = IDL.Func(
|
|
191
|
+
[StreamingToken],
|
|
192
|
+
[IDL.Opt(StreamingCallbackResponse)],
|
|
193
|
+
['query'],
|
|
194
|
+
);
|
|
195
|
+
const StreamingStrategy = IDL.Variant({
|
|
196
|
+
'Callback' : IDL.Record({
|
|
197
|
+
'token' : StreamingToken,
|
|
198
|
+
'callback' : StreamingCallback,
|
|
199
|
+
}),
|
|
200
|
+
});
|
|
201
|
+
const Response = IDL.Record({
|
|
202
|
+
'body' : IDL.Vec(IDL.Nat8),
|
|
203
|
+
'headers' : IDL.Vec(Header),
|
|
204
|
+
'upgrade' : IDL.Opt(IDL.Bool),
|
|
205
|
+
'streaming_strategy' : IDL.Opt(StreamingStrategy),
|
|
206
|
+
'status_code' : IDL.Nat16,
|
|
207
|
+
});
|
|
177
208
|
const PageCount = IDL.Nat;
|
|
178
209
|
const Result_3 = IDL.Variant({ 'ok' : IDL.Null, 'err' : IDL.Text });
|
|
179
210
|
const Result_2 = IDL.Variant({ 'ok' : FileId, 'err' : Err });
|
|
@@ -270,6 +301,7 @@ export const idlFactory = ({ IDL }) => {
|
|
|
270
301
|
'getTotalDownloads' : IDL.Func([], [IDL.Nat], ['query']),
|
|
271
302
|
'getTotalPackages' : IDL.Func([], [IDL.Nat], ['query']),
|
|
272
303
|
'getUser' : IDL.Func([IDL.Principal], [IDL.Opt(User__1)], ['query']),
|
|
304
|
+
'http_request' : IDL.Func([Request], [Response], ['query']),
|
|
273
305
|
'notifyInstall' : IDL.Func(
|
|
274
306
|
[PackageName__1, PackageVersion],
|
|
275
307
|
[],
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Nat "mo:base/Nat";
|
|
2
|
+
import Iter "mo:base/Iter";
|
|
3
|
+
import Buffer "mo:base/Buffer";
|
|
4
|
+
import Vector "mo:vector/Class";
|
|
5
|
+
// import Bench "./bench";
|
|
6
|
+
import Bench "mo:bench";
|
|
7
|
+
|
|
8
|
+
module {
|
|
9
|
+
public func init() : Bench.Bench {
|
|
10
|
+
let bench = Bench.Bench();
|
|
11
|
+
|
|
12
|
+
bench.setName("Add items one-by-one");
|
|
13
|
+
|
|
14
|
+
bench.addRow("Vector");
|
|
15
|
+
bench.addRow("Buffer");
|
|
16
|
+
|
|
17
|
+
bench.addCol("10");
|
|
18
|
+
bench.addCol("10000");
|
|
19
|
+
bench.addCol("1000000");
|
|
20
|
+
|
|
21
|
+
bench.setRunner(func(row, col) {
|
|
22
|
+
let ?n = Nat.fromText(col);
|
|
23
|
+
|
|
24
|
+
// Vector
|
|
25
|
+
if (row == "Vector") {
|
|
26
|
+
let vec = Vector.Vector<Nat>();
|
|
27
|
+
for (i in Iter.range(1, n)) {
|
|
28
|
+
vec.add(i);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Buffer
|
|
32
|
+
else if (row == "Buffer") {
|
|
33
|
+
let buf = Buffer.Buffer<Nat>(0);
|
|
34
|
+
for (i in Iter.range(1, n)) {
|
|
35
|
+
buf.add(i);
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// bench.table(["Vector", "Buffer"], ["10", "10000", "1000000"], func(row, col) {
|
|
41
|
+
// });
|
|
42
|
+
|
|
43
|
+
bench;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Nat64 "mo:base/Nat64";
|
|
2
|
+
import Debug "mo:base/Debug";
|
|
3
|
+
import ExperimentalInternetComputer "mo:base/ExperimentalInternetComputer";
|
|
4
|
+
import Prim "mo:prim";
|
|
5
|
+
|
|
6
|
+
// import Bench "./bench";
|
|
7
|
+
import Bench "mo:bench";
|
|
8
|
+
|
|
9
|
+
import UserBench "$USER_BENCH_FILE";
|
|
10
|
+
|
|
11
|
+
actor class() {
|
|
12
|
+
var benchOpt : ?Bench.Bench = null;
|
|
13
|
+
|
|
14
|
+
public func init() : async Bench.BenchSchema {
|
|
15
|
+
let bench = UserBench.init();
|
|
16
|
+
benchOpt := ?bench;
|
|
17
|
+
bench.getSchema();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// public composite query func noop() : async () {};
|
|
21
|
+
|
|
22
|
+
public func runCell(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
23
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
24
|
+
|
|
25
|
+
let rts_heap_size_before = Prim.rts_heap_size();
|
|
26
|
+
let rts_memory_size_before = Prim.rts_memory_size();
|
|
27
|
+
let rts_total_allocation_before = Prim.rts_total_allocation();
|
|
28
|
+
let rts_mutator_instructions_before = Prim.rts_mutator_instructions();
|
|
29
|
+
let rts_collector_instructions_before = Prim.rts_collector_instructions();
|
|
30
|
+
|
|
31
|
+
let mode : Bench.BenchMode = #replica;
|
|
32
|
+
let instructions = switch(mode) {
|
|
33
|
+
case (#replica) {
|
|
34
|
+
ExperimentalInternetComputer.countInstructions(func() {
|
|
35
|
+
bench.runCell(rowIndex, colIndex, #replica);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
case (#wasi) {
|
|
39
|
+
bench.runCell(rowIndex, colIndex, #replica);
|
|
40
|
+
0 : Nat64;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// await noop();
|
|
45
|
+
|
|
46
|
+
// await (func() : async () {})();
|
|
47
|
+
|
|
48
|
+
{
|
|
49
|
+
instructions = Nat64.toNat(instructions);
|
|
50
|
+
rts_heap_size = Prim.rts_heap_size() - rts_heap_size_before;
|
|
51
|
+
rts_memory_size = Prim.rts_memory_size() - rts_memory_size_before;
|
|
52
|
+
rts_total_allocation = Prim.rts_total_allocation() - rts_total_allocation_before;
|
|
53
|
+
rts_mutator_instructions = Prim.rts_mutator_instructions() - rts_mutator_instructions_before;
|
|
54
|
+
rts_collector_instructions = Prim.rts_collector_instructions() - rts_collector_instructions_before;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Nat "mo:base/Nat";
|
|
2
|
+
import Iter "mo:base/Iter";
|
|
3
|
+
import Buffer "mo:base/Buffer";
|
|
4
|
+
import Vector "mo:vector/Class";
|
|
5
|
+
// import Bench "./bench";
|
|
6
|
+
import Bench "mo:bench";
|
|
7
|
+
|
|
8
|
+
module {
|
|
9
|
+
public func init() : Bench.Bench {
|
|
10
|
+
let bench = Bench.Bench();
|
|
11
|
+
|
|
12
|
+
bench.setName("Add items one-by-one");
|
|
13
|
+
|
|
14
|
+
bench.addRow("Vector");
|
|
15
|
+
bench.addRow("Buffer");
|
|
16
|
+
|
|
17
|
+
bench.addCol("10");
|
|
18
|
+
bench.addCol("10000");
|
|
19
|
+
bench.addCol("1000000");
|
|
20
|
+
|
|
21
|
+
bench.setRunner(func(row, col) {
|
|
22
|
+
let ?n = Nat.fromText(col);
|
|
23
|
+
|
|
24
|
+
// Vector
|
|
25
|
+
if (row == "Vector") {
|
|
26
|
+
let vec = Vector.Vector<Nat>();
|
|
27
|
+
for (i in Iter.range(1, n)) {
|
|
28
|
+
vec.add(i);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Buffer
|
|
32
|
+
else if (row == "Buffer") {
|
|
33
|
+
let buf = Buffer.Buffer<Nat>(0);
|
|
34
|
+
for (i in Iter.range(1, n)) {
|
|
35
|
+
buf.add(i);
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// bench.table(["Vector", "Buffer"], ["10", "10000", "1000000"], func(row, col) {
|
|
41
|
+
// });
|
|
42
|
+
|
|
43
|
+
bench;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Nat "mo:base/Nat";
|
|
2
|
+
import Iter "mo:base/Iter";
|
|
3
|
+
import Buffer "mo:base/Buffer";
|
|
4
|
+
import Vector "mo:vector/Class";
|
|
5
|
+
// import Bench "./bench";
|
|
6
|
+
import Bench "mo:bench";
|
|
7
|
+
|
|
8
|
+
module {
|
|
9
|
+
public func init() : Bench.Bench {
|
|
10
|
+
let bench = Bench.Bench();
|
|
11
|
+
|
|
12
|
+
bench.setName("Add items one-by-one");
|
|
13
|
+
|
|
14
|
+
bench.addRow("Vector");
|
|
15
|
+
bench.addRow("Buffer");
|
|
16
|
+
|
|
17
|
+
bench.addCol("10");
|
|
18
|
+
bench.addCol("10000");
|
|
19
|
+
bench.addCol("1000000");
|
|
20
|
+
|
|
21
|
+
bench.setRunner(func(row, col) {
|
|
22
|
+
let ?n = Nat.fromText(col);
|
|
23
|
+
|
|
24
|
+
// Vector
|
|
25
|
+
if (row == "Vector") {
|
|
26
|
+
let vec = Vector.Vector<Nat>();
|
|
27
|
+
for (i in Iter.range(1, n)) {
|
|
28
|
+
vec.add(i);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Buffer
|
|
32
|
+
else if (row == "Buffer") {
|
|
33
|
+
let buf = Buffer.Buffer<Nat>(0);
|
|
34
|
+
for (i in Iter.range(1, n)) {
|
|
35
|
+
buf.add(i);
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// bench.table(["Vector", "Buffer"], ["10", "10000", "1000000"], func(row, col) {
|
|
41
|
+
// });
|
|
42
|
+
|
|
43
|
+
bench;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Nat64 "mo:base/Nat64";
|
|
2
|
+
import Debug "mo:base/Debug";
|
|
3
|
+
import ExperimentalInternetComputer "mo:base/ExperimentalInternetComputer";
|
|
4
|
+
import Prim "mo:prim";
|
|
5
|
+
|
|
6
|
+
// import Bench "./bench";
|
|
7
|
+
import Bench "mo:bench";
|
|
8
|
+
|
|
9
|
+
import UserBench "$USER_BENCH_FILE";
|
|
10
|
+
|
|
11
|
+
actor class() {
|
|
12
|
+
var benchOpt : ?Bench.Bench = null;
|
|
13
|
+
|
|
14
|
+
public func init() : async Bench.BenchSchema {
|
|
15
|
+
let bench = UserBench.init();
|
|
16
|
+
benchOpt := ?bench;
|
|
17
|
+
bench.getSchema();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// public composite query func noop() : async () {};
|
|
21
|
+
|
|
22
|
+
public func runCell(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
23
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
24
|
+
|
|
25
|
+
let rts_heap_size_before = Prim.rts_heap_size();
|
|
26
|
+
let rts_memory_size_before = Prim.rts_memory_size();
|
|
27
|
+
let rts_total_allocation_before = Prim.rts_total_allocation();
|
|
28
|
+
let rts_mutator_instructions_before = Prim.rts_mutator_instructions();
|
|
29
|
+
let rts_collector_instructions_before = Prim.rts_collector_instructions();
|
|
30
|
+
|
|
31
|
+
let mode : Bench.BenchMode = #replica;
|
|
32
|
+
let instructions = switch(mode) {
|
|
33
|
+
case (#replica) {
|
|
34
|
+
ExperimentalInternetComputer.countInstructions(func() {
|
|
35
|
+
bench.runCell(rowIndex, colIndex, #replica);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
case (#wasi) {
|
|
39
|
+
bench.runCell(rowIndex, colIndex, #replica);
|
|
40
|
+
0 : Nat64;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// await noop();
|
|
45
|
+
|
|
46
|
+
// await (func() : async () {})();
|
|
47
|
+
|
|
48
|
+
{
|
|
49
|
+
instructions = Nat64.toNat(instructions);
|
|
50
|
+
rts_heap_size = Prim.rts_heap_size() - rts_heap_size_before;
|
|
51
|
+
rts_memory_size = Prim.rts_memory_size() - rts_memory_size_before;
|
|
52
|
+
rts_total_allocation = Prim.rts_total_allocation() - rts_total_allocation_before;
|
|
53
|
+
rts_mutator_instructions = Prim.rts_mutator_instructions() - rts_mutator_instructions_before;
|
|
54
|
+
rts_collector_instructions = Prim.rts_collector_instructions() - rts_collector_instructions_before;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import Nat64 "mo:base/Nat64";
|
|
2
|
+
import Nat "mo:base/Nat";
|
|
3
|
+
import Debug "mo:base/Debug";
|
|
4
|
+
import ExperimentalInternetComputer "mo:base/ExperimentalInternetComputer";
|
|
5
|
+
import Prim "mo:prim";
|
|
6
|
+
import Bench "mo:bench";
|
|
7
|
+
|
|
8
|
+
import UserBench "./user-bench";
|
|
9
|
+
|
|
10
|
+
actor class() {
|
|
11
|
+
var benchOpt : ?Bench.Bench = null;
|
|
12
|
+
|
|
13
|
+
public func init() : async Bench.BenchSchema {
|
|
14
|
+
let bench = UserBench.init();
|
|
15
|
+
benchOpt := ?bench;
|
|
16
|
+
bench.getSchema();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
func _getStats() : Bench.BenchResult {
|
|
20
|
+
{
|
|
21
|
+
instructions = 0;
|
|
22
|
+
rts_heap_size = Prim.rts_heap_size();
|
|
23
|
+
rts_memory_size = Prim.rts_memory_size();
|
|
24
|
+
rts_total_allocation = Prim.rts_total_allocation();
|
|
25
|
+
rts_mutator_instructions = Prim.rts_mutator_instructions();
|
|
26
|
+
rts_collector_instructions = Prim.rts_collector_instructions();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
func _runCell(rowIndex : Nat, colIndex : Nat) : Bench.BenchResult {
|
|
31
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
32
|
+
let statsBefore = _getStats();
|
|
33
|
+
|
|
34
|
+
let instructions = ExperimentalInternetComputer.countInstructions(func() {
|
|
35
|
+
bench.runCell(rowIndex, colIndex);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// await (func() : async () {})();
|
|
39
|
+
|
|
40
|
+
let statsAfter = _getStats();
|
|
41
|
+
|
|
42
|
+
{
|
|
43
|
+
instructions = Nat64.toNat(instructions);
|
|
44
|
+
rts_heap_size = statsAfter.rts_heap_size - statsBefore.rts_heap_size;
|
|
45
|
+
rts_memory_size = statsAfter.rts_memory_size - statsBefore.rts_memory_size;
|
|
46
|
+
rts_total_allocation = statsAfter.rts_total_allocation - statsBefore.rts_total_allocation;
|
|
47
|
+
rts_mutator_instructions = statsAfter.rts_mutator_instructions - statsBefore.rts_mutator_instructions;
|
|
48
|
+
rts_collector_instructions = statsAfter.rts_collector_instructions - statsBefore.rts_collector_instructions;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
func _runCellAwait(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
53
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
54
|
+
let statsBefore = _getStats();
|
|
55
|
+
|
|
56
|
+
let instructions = ExperimentalInternetComputer.countInstructions(func() {
|
|
57
|
+
bench.runCell(rowIndex, colIndex);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
await (func() : async () {})();
|
|
61
|
+
|
|
62
|
+
let statsAfter = _getStats();
|
|
63
|
+
|
|
64
|
+
{
|
|
65
|
+
instructions = Nat64.toNat(instructions);
|
|
66
|
+
rts_heap_size = statsAfter.rts_heap_size - statsBefore.rts_heap_size;
|
|
67
|
+
rts_memory_size = statsAfter.rts_memory_size - statsBefore.rts_memory_size;
|
|
68
|
+
rts_total_allocation = statsAfter.rts_total_allocation - statsBefore.rts_total_allocation;
|
|
69
|
+
rts_mutator_instructions = statsAfter.rts_mutator_instructions - statsBefore.rts_mutator_instructions;
|
|
70
|
+
rts_collector_instructions = statsAfter.rts_collector_instructions - statsBefore.rts_collector_instructions;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
public query func getStats() : async Bench.BenchResult {
|
|
75
|
+
_getStats();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
public query func runCellQuery(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
79
|
+
_runCell(rowIndex, colIndex);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
public func runCellUpdate(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
83
|
+
await _runCellAwait(rowIndex, colIndex);
|
|
84
|
+
};
|
|
85
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const idlFactory = ({ IDL }) => {
|
|
2
|
+
const BenchSchema = IDL.Record({
|
|
3
|
+
'title': IDL.Text,
|
|
4
|
+
'cols': IDL.Vec(IDL.Text),
|
|
5
|
+
'rows': IDL.Vec(IDL.Text),
|
|
6
|
+
'description': IDL.Text,
|
|
7
|
+
});
|
|
8
|
+
const BenchResult = IDL.Record({
|
|
9
|
+
'instructions': IDL.Nat,
|
|
10
|
+
'rts_memory_size': IDL.Nat,
|
|
11
|
+
'rts_total_allocation': IDL.Nat,
|
|
12
|
+
'rts_collector_instructions': IDL.Nat,
|
|
13
|
+
'rts_mutator_instructions': IDL.Nat,
|
|
14
|
+
'rts_heap_size': IDL.Nat,
|
|
15
|
+
});
|
|
16
|
+
const anon_class_11_1 = IDL.Service({
|
|
17
|
+
'init': IDL.Func([], [BenchSchema], []),
|
|
18
|
+
'runCell': IDL.Func([IDL.Nat, IDL.Nat], [BenchResult], []),
|
|
19
|
+
});
|
|
20
|
+
return anon_class_11_1;
|
|
21
|
+
};
|
|
22
|
+
export const init = ({ IDL }) => { return []; };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Actor, HttpAgent } from "@dfinity/agent";
|
|
2
|
+
// Imports and re-exports candid interface
|
|
3
|
+
import { idlFactory } from "./bench.did.js";
|
|
4
|
+
export { idlFactory } from "./bench.did.js";
|
|
5
|
+
/* CANISTER_ID is replaced by webpack based on node environment
|
|
6
|
+
* Note: canister environment variable will be standardized as
|
|
7
|
+
* process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
|
|
8
|
+
* beginning in dfx 0.15.0
|
|
9
|
+
*/
|
|
10
|
+
export const canisterId = process.env.CANISTER_ID_BENCH ||
|
|
11
|
+
process.env.BENCH_CANISTER_ID;
|
|
12
|
+
export const createActor = (canisterId, options = {}) => {
|
|
13
|
+
const agent = options.agent || new HttpAgent({ ...options.agentOptions });
|
|
14
|
+
if (options.agent && options.agentOptions) {
|
|
15
|
+
console.warn("Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent.");
|
|
16
|
+
}
|
|
17
|
+
// Fetch root key for certificate validation during development
|
|
18
|
+
if (process.env.DFX_NETWORK !== "ic") {
|
|
19
|
+
agent.fetchRootKey().catch((err) => {
|
|
20
|
+
console.warn("Unable to fetch root key. Check to ensure that your local replica is running");
|
|
21
|
+
console.error(err);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// Creates an actor with using the candid interface and the HttpAgent
|
|
25
|
+
return Actor.createActor(idlFactory, {
|
|
26
|
+
agent,
|
|
27
|
+
canisterId,
|
|
28
|
+
...options.actorOptions,
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Actor, HttpAgent } from "@dfinity/agent";
|
|
2
|
+
// Imports and re-exports candid interface
|
|
3
|
+
import { idlFactory } from "./main.did.js";
|
|
4
|
+
export { idlFactory } from "./main.did.js";
|
|
5
|
+
/* CANISTER_ID is replaced by webpack based on node environment
|
|
6
|
+
* Note: canister environment variable will be standardized as
|
|
7
|
+
* process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
|
|
8
|
+
* beginning in dfx 0.15.0
|
|
9
|
+
*/
|
|
10
|
+
export const canisterId = process.env.CANISTER_ID_MAIN ||
|
|
11
|
+
process.env.MAIN_CANISTER_ID;
|
|
12
|
+
export const createActor = (canisterId, options = {}) => {
|
|
13
|
+
const agent = options.agent || new HttpAgent({ ...options.agentOptions });
|
|
14
|
+
if (options.agent && options.agentOptions) {
|
|
15
|
+
console.warn("Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent.");
|
|
16
|
+
}
|
|
17
|
+
// Fetch root key for certificate validation during development
|
|
18
|
+
if (process.env.DFX_NETWORK !== "ic") {
|
|
19
|
+
agent.fetchRootKey().catch((err) => {
|
|
20
|
+
console.warn("Unable to fetch root key. Check to ensure that your local replica is running");
|
|
21
|
+
console.error(err);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// Creates an actor with using the candid interface and the HttpAgent
|
|
25
|
+
return Actor.createActor(idlFactory, {
|
|
26
|
+
agent,
|
|
27
|
+
canisterId,
|
|
28
|
+
...options.actorOptions,
|
|
29
|
+
});
|
|
30
|
+
};
|