There are many reasons for wanting to know your mileage, and it is not clear why you want to know. Not understanding the question never stopped any of us from providing authoritative answers. So:
The map is your best guide. Some of it depends on where you hike. The AT corkscrews through the woods, up, down and sideways and the big corkscrews have little corkscrews to avoid boredom. It's Baroque. The Colorado Trail and CDT stretch like lazy snakes along the ridges - with moderate elevation change. Heck, you can just look at your mileage in person - most of a day's hike in sight. That said:
(1) GPS will give you accurate mileage in conjunction with a map or if you are using a unit loaded with the trail you are hiking.
(2) Pedometers rarely give consistent readings on rough trails because you change stride length when changing from level to climbs or descents.
(3) Since most folks have different hiking rates on different trails and different states of fatigue, your watch (the time you take) may not be terribly accurate either. However, on a long hike, in consistent terrain, you may develop a feel for how far you go in an hour - on the average, over the long haul - which may give you a rough way to estimate mileage as you go along.
(4) The map (and on the trail, the compass) will show where you are, how far you have to go and have been. You can use a map wheel or string to estimate mileage from the map. Most trail guides give mileage between significant waypoints. You can mark up the specific trail on your map with that mileage data so you don't have to carry the trail guide.