Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[C] Which is faster?

Name: Anonymous 2010-07-13 5:57


if(a > 3)
{
  int expected_b = fun(a);
  if(good_enough(b, expected_b))
  {
    do_stuff();
  }
}


VS


int expected_b = fun(a);
if(a > 3 && good_enough(b, expected_b))
{
  do_stuff();
}


This is done a shitload of times. fun(a) is a simple linear function.

Name: Anonymous 2010-07-13 20:20

The first one will be faster since there is one less call to make for a<=3. Even that's the case only once, it'd be enough.

Have some pseudo-assembly:
  cmp a,3
  jle cont
;rest
cont:

vs.
  call fun
  mov b, result
  cmp a,3
  jle cont
;rest
cont:

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List