When I looked at ways to survive/evade blockades with 20th century Germany in mind as a thought experiment, this issue came up. Normally diesel locomotives would be better, but since oil products are scarce in a hypothetical blockade I thought that sticking to steam locomotives would be preferred in this case. Their plentiful and cheap solid hydrocarbon (coal) supplies would presumably give them an advantage in simply having fuel available at all.
However, I found that even this was not the case. When checking the efficiency of early diesels (not the 35-40% efficient diesels of today),
I found a WWII-era diesel locomotive produced about 15 horsepower per gallon per hour (i.e. 15 horsepower-hours per gallon). No. 2 Diesel fuel has an energy content of 128,100 BTUs per gallon by the same source, and from another source
a horsepower hour is equal to 2544.43 BTUs. This gives 38,166.5 BTUs of usable energy per gallon of a WWII-era diesel, or about 30% efficiency for the diesel.
By comparison, Andre Chapelon's steam locomotive rebuilds at the end of the steam era (1930's to 1940's) reached 12% efficiency, double the efficiency of the average locomotives of the time and a world record for decades (long after the end of the steam era). So the WWII-era diesel was 5 times as thermally efficient as the average locomotive, and 2.5 times as thermally efficient as the most efficient steam locomotive built.
This disparity was so great that I checked the thermal efficiency of the Fischer-Tropsch process for creating diesel from solid hydrocarbons to see if the greater efficiency of diesels made up for any inefficiency in using this process to convert available solid hydrocarbons to diesel. To my surprise, the process was more efficient than I thought, being about 25 to 50% efficient in both carbon and thermal efficiency. Using a diesel locomotive with fuel from an inefficient (25%) Fischer-Tropsch plant would still be 1.25 times as thermally efficient as using an average steam locomotive, and using it with fuel from an efficient (50%) Fischer-Tropsch plant would again be 1.25 times as thermally efficient as using the most efficient steam locomotive. So it literally requires less coal to provide a Fischer-Tropsch plant with fuel and burn the resulting diesel in a locomotive to move cargo, than it does to burn the coal directly in a steam locomotive. Any cost to run the Fischer-Tropsch plant would likely be offset by the greatly reduced maintenance costs, reduced idling fuel consumption of the diesels, lower transportation requirements for moving coal to the plant and moving fuel to the locomotive vs moving the greater mass of coal all the way to the locomotive, and in the elimination of water requirements, all of which have not been factored in to the above calculations.
Of course, the ideal choice is to electrify the railroads so that the fuel can be burned in a very efficient power plant with little efficiency loss, but electrifying an entire railway network can be impractical even over a long period of time. So the best option is to electrify whatever is possible and make sure all non-electric locomotives are dual-mode so they can use the network whenever possible without using fuel. (It seems easy to make dual-mode locomotives based on diesel-electrics, so much so that I wonder why it hasn't been done with almost all diesel-electrics- it seems a missed opportunity) The latter mode of propulsion for locomotives not on electrified lines is generally what the diesel Fischer-Tropsch is intended for.
There are some steam locomotive improvements since WWII by Porta that potentially improve the efficiency of the locomotive to 21% or 27% with condensing, and many of these technologies could theoretically be developed prior to WWII, but it's not certain and it seems these engines would still be outperformed if a similar amount of development was put into improving the efficiency of diesels and the Fischer-Tropsch process. Steam turbine-electric (turbo-electric) locomotives might actually be efficient enough with such boiler improvements to be viable, but they're not covered in this analysis, and even then I'm not sure about it (I'd still stick to diesel and Fischer-Tropsch, which seems a better bet).
The general lesson deduced from these calculations was that in places/situations where liquid hydrocarbon fuels are scarce or restricted, obviously the best solution is to reduce requirements for energy or transportation. But if something must be mechanized, mechanizing with solid hydrocarbon fuels (coal, wood gas, etc) or god forbid animal power is less efficient than using the solid hydrocarbons to run the Fischer-Tropsch process and then mechanizing with the resulting liquid hydrocarbon fuels (ideally diesel for efficiency). (Animal power is best compared by calculating the land requirements for growing fodder versus the amount of biofuels that could be grown on the same land and how much fuel it could produce if used in the Fischer-Tropsch process) Steam versus diesel locomotives are a subset of this comparison.