I don't understand why you'd ask when the person is right there with you. You can see how tall they are. I'm the average height of men where I live, and for whatever reason the tall guys here 95% of the time seem to date short women (which looks really weird to me but I'm the product of a union just like that - mom 5'4" dad 6'4", so maybe it's nature trying not to breed us into giants). I have really mostly only dated guys within an inch or two of my height, in both directions. Husband is almost exactly my height. Which all makes sense since such a large chunk of the guys here are close to my height.
Anyway - I don't ask, but have been asked, quite accusingly sometimes, as though I am being tall to make a guy feel short and they are offended.
Tbf I think this is an american thing. I have never asked someone for their hight, nor ever seen anyone ask this. American women are obsessed with men hight.
I get more people saying to me “wow you’re very tall” to which I respond with “yes and you are very observant” which I feel is funny in the moment but is just condescending enough to make them realize it later on.