Post
Share your knowledge.
Performance difference between modulo and comparison assertions?
I'm curious if using assert!(arg3 % arg0 == 0, 6);
is more gas efficient than assert!(arg3 < arg0, 6);
? I came across this in deepbook and was wondering about the choice. Is there any significant performance difference between using modulo versus comparison assertions in terms of gas consumption?
- Move CLI
- Move
Answers
1The latter (assert!(arg3 < arg0, 6);
) will be slightly cheaper in terms of gas because it's a single instruction (Cmp) rather than three (Mod, LdConst<0>, Eq). However, it's generally not something to worry about due to gas bucketing. Arithmetic instructions tend to be much cheaper compared to other instructions. Also, the Sui gas model charges differently only for programs with consistently different wall-clock execution times, and arithmetic execution timings can naturally vary quite a bit. More details can be found in the Sui tokenomics documentation: https://docs.sui.io/concepts/tokenomics/gas-in-sui#computation.
Do you know the answer?
Please log in and share it.
Move is an executable bytecode language used to implement custom transactions and smart contracts.