-
Notifications
You must be signed in to change notification settings - Fork 107
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
benchmark and improve rounding #732
Conversation
defTrunc n desc op = defRNative n fun (funType tTyDecimal [("x",tTyDecimal),("prec",tTyInteger)] <> | ||
unaryTy tTyInteger tTyDecimal) | ||
[ ExecExample $ "(" <> asString n <> " 3.5)" | ||
, ExecExample $ "(" <> asString n <> " 100.15234 2)" | ||
] | ||
(desc <> " value of decimal X as integer, or to PREC precision as decimal.") | ||
where fun :: RNativeFun e | ||
fun _ [TLiteral (LDecimal d) _] = return $ toTerm $ op d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The big surprise here is truncate . roundTo' op 0
is much, much faster (~6us) than using RealFrac
methods directly on Decimal
(~22us)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow weird.
@@ -393,7 +393,7 @@ Return ID if called during current pact execution, failing if not. | |||
Obtain current pact build version. | |||
```lisp | |||
pact> (pact-version) | |||
"3.3.0" | |||
"3.3.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
defTrunc n desc op = defRNative n fun (funType tTyDecimal [("x",tTyDecimal),("prec",tTyInteger)] <> | ||
unaryTy tTyInteger tTyDecimal) | ||
[ ExecExample $ "(" <> asString n <> " 3.5)" | ||
, ExecExample $ "(" <> asString n <> " 100.15234 2)" | ||
] | ||
(desc <> " value of decimal X as integer, or to PREC precision as decimal.") | ||
where fun :: RNativeFun e | ||
fun _ [TLiteral (LDecimal d) _] = return $ toTerm $ op d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow weird.
Fixes #644
Huge improvement to both overloads of decimal rounding! With benchmarks. See #644 for benchmark comparisons.