79093013

Date: 2024-10-16 08:04:30
Score: 1
Natty:
Report link

c++ moment

Result:

if-else = 419813
ternary = 587712

code:

unsigned long timer1, timer2;
volatile uint32_t x;

timer1 = micros();
for (uint32_t iterator = 0; iterator < 10000000; iterator++)
{
  if (iterator & 1)
  {
    x = 1;
  }
  else
  {
    x = 2;
  }
}
timer1 = micros() - timer1;

timer2 = micros();
for (uint32_t iterator = 0; iterator < 10000000; iterator++)
{
  x = (iterator & 1) ? 1 : 2;
}
timer2 = micros() - timer2;

LOG("if-else = ");
LOGLN(timer1);
LOG("ternary = ");
LOGLN(timer2);
Reasons:
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: NekoSamurai