Reliably measuring the energy consumption of arduino running sketch I would like to know if there is a programmatic way of measuring the energy consumption of a sketch or at least if this is possible via external devices. 

My aim is to compare the energy consumption of two devices, connected to usb, running slightly modified versions of the same sketch e.g., one using crypto and one without using crypto.
programmatic way of measuring t


Not sure what you meant by that but typically you can use a high side current sense amplifier to get a measurement of the current. Then adv a known voltage to get vcc. That known voltage could be the internal reference, if available 

In some cases a resistor on vcc can be used to measure current, together with two dividers.