Page 2 of 2

Re: Get value of function with variable

Posted: Mon Sep 14, 2020 11:08 pm
by jacque
mwieder wrote: Mon Sep 14, 2020 6:42 pm Is there an advantage there to using "value" instead of dispatching the function to the card?
Not particularly, but it's a convenient one-liner when you want to get a value back. So yeah, either way works unless the developer is a line-counting absessive I guess.

Actually, come to think of it, dispatch may have the advantage of not requiring the compiler to load. Hadn't thought of that.

Re: Get value of function with variable

Posted: Tue Sep 15, 2020 1:58 am
by mwieder
Haven't looked at this, but my guess is that "value" does the same sort of runtime parsing as "do", so yes, I'd expect it to be slower.
Hmmm... should be an easy benchmark... <goes back to the laboratory>

Re: Get value of function with variable

Posted: Tue Sep 15, 2020 2:08 am
by mwieder
Yep... "dispatch" turns out to be about 5 times faster than an equivalent "value".

Re: Get value of function with variable

Posted: Tue Sep 15, 2020 5:52 am
by jacque
Right, I had heard somewhere that the only two commands/functions that load the compiler are "do" and "value" but I hadn't thought about that in relation to dispatch. I usually go out of my way to avoid "do". I should be more consistent.

"Dispatch" certainly requires less punctuation. :)

Re: Get value of function with variable

Posted: Tue Sep 15, 2020 4:55 pm
by mwieder
I avoid "do" whenever possible for the slowness reason.
I use dispatch frequently, just have to remember that it returns a three-state value: handled, unhandled, and passed.
So I've gotten into the habit of checking "if it is not unhandled" rather than "if it is handled" after a dispatch call.