The previous question motivated me to study this question more deeply, and to write some open-source software to do the relevant calculations. Along the way, I learned that a lot of what people believe about this subject seems to be wrong.
People have traditionally tried to quantify this kind of thing using two numbers that can be pretty easily estimated from a paper topo map: the horizontal distance and the total elevation gain, i.e., the sum of all the elevation increases, not counting any of the elevation decreases. So for example, if we start from sea level, climb to the summit of a mountain that is 3000 meters tall, and then come back down to our starting point, the total gain is not zero (because we don't count the descent), and is greater than or equal to 3000 meters. It can be greater because you may do some up-down-up-down stuff rather than just steadily climbing to the top and then steadily descending back down.
Using the horizontal distance makes sense, because laboratory studies of people running and walking on treadmills show that distance is an extremely important factor. It simply takes energy to put one foot in front of the other.
But the total gain turns out to be a very poor measure of energy expenditure. The energetic cost of running or walking does depend on the slope i, but for the values of i usually encountered in the real world, this slope dependence is not very big. Even a trail that people perceive as extremely steep will typically have a slope of only about 0.03, i.e., 3 meters of elevation gain for every 100 meters of horizontal travel. Furthermore, most hiking and running routes are loops or out-and-backs, so that you end up at the same elevation where you started. Except on extremely steep downhill grades, going downhill is more efficient than walking on flat ground. The result is that the effects of any climbing and descending tend to cancel out unless the terrain is extremely steep. In mathematical terms, the energy cost per meter of horizontal travel is a function E(i), where i is the slope, and although this function has some curvature, the curvature is not very strong, so in most cases the average of E(i) and E(-i) is pretty close to E(0), the cost of flat hiking.
Here are three illustrative examples, with energy costs computed using the data from the paper by Minetti (ref. below), for a 66 kg person:
A. Run 20 km on flat terrain. Cost: 1130 calories.
B. Run 10 km up a steady grade, gaining 1000 meters of elevation, and then run back down, for a total distance of 20 km. Cost: 1133 calories.
C. Run 5 km up a hill 1000 meters tall, then down the back of the hill, another 5 km. (The climb and the descent are both steady.). Run another 10 km on the flats, for a total distance of 20 km and 1000 meters of total gain. Cost: 1415 calories.
D. Run 20 km up a steady grade, gaining 1000 meters of elevation. Ride home in a car. Cost: 1876 calories.
If we describe these runs in the traditional way, then A is 20 km with no gain, while B, C, and D are each 20 km with 1000 meters of gain. However, the energy costs of A and B are about the same, C is a little higher, and D is vastly greater. That's because in examples like B and C, the improved efficiency coming downhill nearly cancels the cost of climbing.
In the software I wrote, I tried to find a simple statistic that would help people to more accurately characterize how hard a certain run or hike would be. What I came up with was something I call the "climb fraction," or CF. It's defined as the fraction of your energy that was spent on climbing. For example, if you compare runs A and D above, the CF for run D is (1876-1130)/1876, or about 40%. Studying the stats for one of my favorite trail runs near my house, which I consider fairly hilly, I was demoralized to learn that its CF was only 1%.
After I wrote this, I came across a very similar treatment of the problem by R. Baumel, referenced below.
Baumel, Bob, "Hill effect to second order," Measurement News, January 1989, #33, p. 36, http://www.runscore.com/coursemeasurement/MeasurementNews/033_89a.pdf
Baumel, Bob and Jones, Alan, "Uphills, downhills, and the Boston marathon," Measurement News, March 1990, #40, p. 15, http://www.runscore.com/coursemeasurement/MeasurementNews/040_90a.pdf
Minetti et al. "Energy cost of walking and running at extreme uphill and downhill slopes," J. Applied Physiology 93 (2002) 1039, http://jap.physiology.org/content/93/3/1039.full