These devices are THREE terminal regulators. One pin is the input, another the output. Any current that does not flow from input to output will reduce the efficiency beyond the mathematical minimum of (Vout-Vin)*Iout

As each device comes in several varieties we need to pick an apple to compare to an apple, so I looked at the TO-220 package rated for 1A output current on each. The 7805 has a nominal third terminal current of 5 to 8 mA. (It is labeled "Quiescent Current.") The LM317 had a third terminal current of just 46-100 uA (labeled "Adjustable pin Current").

So the LM317 takes a smidgen less current to operate, but I would hesitate to call a 7.9 mA difference out of 1,000 mA anything but a marginal improvement.

You are misinterpreting the meaning of the word "efficiency".
Just because one device gets hotter than another is not a measure of efficiency.

As others have already pointed out, every linear voltage regulator has to drop the excess voltage and this is lost as wasted heat. If your load consumes 100mA @5V from a 24V source, the voltage drop is 24V - 5V = 19V.
The regulator has to dissipate 19V x 100mA = 1.9W
This is the same for both regulators.

What you have not told us is the load on each regulator.

What you are most likely experiencing as excess heat is the "quiescent" current of the regulator with no load attached.

This can't possibly be true. "Efficiency" of a linear regulator is a meaningless concept; its function is to throw energy away. When it heats up, it's just doing its job, and if the component is cold, it must be because it's not loaded. If you could feel any heat in either regulator with no load on the output, something was wrong.

Edited to ask if you're aware that the LM317 and the LM7805 have different pinouts. If you put one on a power supply with the same connections as the other, you may indeed find some heat being generated!