Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: define ExperimentalInternetComputer.performanceCounter : Nat32 -> Nat64; #600

Merged
merged 4 commits into from
Nov 27, 2023

Conversation

crusso
Copy link
Contributor

@crusso crusso commented Nov 23, 2023

Returns the current value of IC performance counter counter:

  • Counter 0 is the current execution instruction counter, counting instructions only since the beginning of the current IC message.
    This counter is reset to value 0 on shared function entry and every await.
    It is therefore only suitable for measuring the cost of synchronous code.

  • Counter '1' is the call context instruction counter for the current call context.
    For replicated message executing, this excludes the cost of nested IC calls (even to the current canister).
    For non-replicated messages, such as composite queries, it includes the cost of nested calls.
    The current value of this counter is preserved across awaits (unlike counter 0).

  • The function (currently) traps if counter >= 2.

Consult Performance Counter for details.

Example:

import IC "mo:base/ExperimentalInternetComputer";
  ///
let c1 = IC.performanceCounter(1);
work();
let diff : Nat64 = IC.performanceCounter(1) - c1;

@crusso crusso changed the title define ExperimentalInternetComputer.performanceCounter : Nat32 -> Nat64; feat: define ExperimentalInternetComputer.performanceCounter : Nat32 -> Nat64; Nov 23, 2023
@crusso crusso enabled auto-merge (squash) November 23, 2023 18:51
Copy link
Contributor

@luc-blaeser luc-blaeser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Nice documentation.
(Regarding the underlying IC specification: Very special semantics for the counter 1, with different counting for replicated and non-replicated messages...)

@crusso crusso merged commit 34a6210 into master Nov 27, 2023
6 checks passed
@crusso crusso deleted the claudio/IC-perf-count branch November 27, 2023 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants