I generally worry more about the ups and downs themselves than the extra distance they introduce.
However . . . if you can obtain a linear elevation profile and divide it into sections of approximately continuous slope, these become right triangles to which you can apply the Pythagorean theorem (length of hypoteneuse is the square root of the sum of the squares of the other two sides, that is, the elevation gain and the map distance (in same units of course)).
For hiking this is probably a waste of time. Consider that even for a strenuous 20 % grade (about 1000 feet gained in a mile), you only travel an additional 94 feet, less than 2 % of the total. Insignificant additonal effort compared to the effort needed to get you up that 1000 vertical feet. In addition, most trails, even relatively "straight up/down" sections have a fair amount of "micro-elevation gain/loss" e.g. up 10 feet, down 10 feet, up 30 feet, down 5 feet. In fact, the total elevation change increases as the granularity of measurement becomes finer. Another way of saying this is that it possess a fractal dimension greater than 1. If you could measure down to the individual grains of sand the total would be astronomical, but of course the finest scale relevant to our concerns is the vertical distance between human strides, which is still much finer than most published figures seem to be based on. I've seen altimeter totals (with ~ 2 ft resolution) nearly double published figures for some sections of trail. Granted, some of this discrepancy may be due to altimeter drift being recorded as gain / loss, but a large component seems to be this micro elevation change. So this calls into question the relevance of published figures for this purpose (or map-calculated ones, most 24k topos for mountainous regions have a 20 meter contour distance).
However, since you ARE posting this to the mountaineering / alpinism forum, I'll assume you are talking about slope angles much greater than a 20 % grade. In that case obviously the elevation gain is a much higher component of your travel across the map. Also the more vertical routes seem to be generally more continuously up/down, without so much "micro." Here I'll defer to someone with actual experience in this area, since I have zero. But, IMHO it seems that, if the purpose of this exercise is to approximate energy consumption / strenousness of different routes, then again, the vertical component will be far more significant than the "diagonal" component you want to calculate.
Hope this helps.