Hey @firepol !
If you haven’t already done so, when calling the
createPerson function with each of the different control flow statements, click on Debug next to the transaction detail (bottom right) to open the Debugger. You can click forward through the different operations contained within the
createPerson function until you get to the first one associated with the control flow statement you are testing (you will know as the associated code is highlighted). As you then click through all the operations associated with that particular piece of code, you will notice the different amounts of gas used for each operation. I basically added up all the amounts for each different control flow statement and compared the totals.
I was interested to see that you used the ternary operator differently to me:
age >= 65 ? newPerson.senior = true : newPerson.senior = false;
So, I’ve tested your ternary operator as well, and with optimization OFF, the gas is the same as with my ternary operator (80), and only 2 less than mine with optimization ON (73 instead of 75).
It’s also worth bearing in mind that in your ternary operator, the
? true : false part is actually redundant, because the expression
age >= 65 will return
false anyway. So just as you’ve already realised, the prize for Sexiest Control Flow Statement (or at least Cheapest) goes to…
And thanks, because looking in more detail at your version of the ternary operator has made me realise that in the end
newPerson.senior = age >= 65; is actually a condensed form of my ternary operator as well!