-
Notifications
You must be signed in to change notification settings - Fork 18
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
Question regarding performance hacks #35
Comments
To me the second variant is quicker. In both minimal MeTTa and Rust interpreter. |
Apparently, nested
uses non-determinism for a deterministic function, which is definitely not an idiomatic way to implement it, and involves
Whether to use
to this
is exactly the place where |
It is weird, but you're right. It was quite opposite on the previous metta versions for me. I haven't tested time difference between these two variants after updating metta. |
@Necr0x0Der Thank you for explanations. One question regarding
as I understand for (== $n 0) result will be 0, for (== $n 1) result will be 1, for $_ (everything else?) result will be sum of recursions. Is this symbol |
In MeTTa it is just a normal variable. Name |
Thanks, Vitaly. |
There was an inner conversation regarding my suggestion on how to improve performance of some functions. This issue is the result of this conversation. I'm wrapping it here since it could be useful for those who starts to learn Metta.
So, let's start with a code. Here is a two possible ways to implement factorial:
And, similarly, two ways to implement Fibonacci number generator:
In each example, second implementation is faster than first one. For example, (fib 100) vs (fib2 100) is 48.808s vs 19.594s . And bigger the input number - bigger the difference in performance. Difference for factorial is not so impressive. At least for 100 as input. 10.303s vs 9.703s .
Anyway, @Necr0x0Der said that these hacks is not appropriate since they can be applied only to current state of metta interpreter and further interpreter optimizations could make these hacks obsolete. So better way to implement fib will be one of those:
Iterative variant should be quicker, but in current metta interpreter's state it is quite opposite due to interpreter cashes all calls during evaluation (@Necr0x0Der will probably explain this better). In minimal-metta this behavior could be different.
The text was updated successfully, but these errors were encountered: