implicit return? [🇷 for BE/BA]

posted by ElMaestro  – Denmark, 2019-04-29 11:40 (1821 d 20:43 ago) – Posting: # 20260
Views: 6,575

Hi Hötzi,


Interestingly (at least to moi!), I tried out of curiosity to do this:

QWERTY=function(x)
{
 ifelse ((x==0), "foo", "bar")
}


The benchmark for this version is much, much slower than any of the other proposals (at least on my system). Another example that shows that condensing code towards fewer keystrokes is not always fastest. I wonder what goes on internally since this is much slower? Perhaps space is allocated for both "foo" and "bar" in memory and then there is a decision as to which one to throw away and which one to keep on the CPU stack? I don't have a very good at understanding of these things.

This one is appearing even worse:
QWERTY2=function(x)
{
 ifelse (x, "bar", "foo")
}


I have no idea why QWERTY2 would not outperform QWERTY or at least be the same if R has a kind of optimiser in the interpreter. Would you happen know????

Pass or fail!
ElMaestro

Complete thread:

UA Flag
Activity
 Admin contact
22,993 posts in 4,828 threads, 1,659 registered users;
59 visitors (0 registered, 59 guests [including 5 identified bots]).
Forum time: 08:23 CEST (Europe/Vienna)

So far as I can remember,
there is not one word in the Gospels
in praise of intelligence.    Bertrand Russell

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5