Hello everyone!
I have been experimenting with benchmarking Motoko canisters and developed my own set of functions in TypeScript that can be used to perform complex Motoko canister benchmarking in Node with the structure you define.
Can be used to measure performance of data structures, function calls, controlling the state of used resources of a canister, resource usage of different garbage collectors.
It uses the same principles as bench to measure rts data of a canister but with some improvements:
-
Number of measured parameters is expanded;
-
Support for complex testing scenarios due to increased flexibility;
-
Can be used with other TypeScript libraries and manipulate local dfx environment from code and not from terminal;
-
Can test standalone canisters which contain stable variables;
-
Can freely manipulate the results of tests to obtain more precise results (as shown in example later);
-
Can measure performances of a single function call or multiple ones (by adding or substracting measurement results);
-
Results can be saved to Excel which is useful for situations when we are bulk testing.
It allows to measure:
rts_stable_memory_size: bigint; //Stable memory pages used
rts_memory_size: bigint; //Total memory used by canister
rts_total_allocation: bigint; //Total allocated memory of all time
rts_reclaimed: bigint; //Total reclaimed memory of all time
rts_heap_size: bigint; //Used Heap memory size of canister in bytes
instruction_count: bigint; //Instruction cost of performing operations without costs for calling the function and returning values
rts_collector_instructions: bigint; //Instructions that are used for garbage collection;
rts_mutator_instructions: biging; //Total Wasm instructions used by the last called update function, except for garbage collection
Note: if you want to measure GC instructions per function call, use flag "--force-gc" with the type if gc you want to use in dfx.json:
"--generational-gc" - use generational GC,
"--incremental-gc" - use incremental GC,
"--compacting-gc" - use compacting GC,
"--copying-gc" - use copying GC (default)
For example, if you want to measure the function resource usage with --incremental-gc:
"defaults": {
"build": {
"args": "--force-gc --incremental-gc",
...
}
},
Available on:
If you have any questions or find any bugs please message me - I will be happy to reply
2 Likes