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

benchmark and improve rounding #732

Merged
merged 1 commit into from
Nov 16, 2019
Merged

benchmark and improve rounding #732

merged 1 commit into from
Nov 16, 2019

Conversation

sirlensalot
Copy link
Contributor

Fixes #644

Huge improvement to both overloads of decimal rounding! With benchmarks. See #644 for benchmark comparisons.

@sirlensalot sirlensalot requested a review from emilypi November 16, 2019 22:27
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
Copy link
Contributor Author

@sirlensalot sirlensalot Nov 16, 2019

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)

Copy link
Member

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"
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Wow weird.

@sirlensalot sirlensalot merged commit f9e3f04 into master Nov 16, 2019
@sirlensalot sirlensalot deleted the feat/improve-rounding branch November 16, 2019 23:00
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.

Improve ceiling/round/floor performance and adjust gas price
2 participants