How do get elapsed time in milliseconds in a shell script?

From: Frank Leonhardt <freebsd-doc_at_fjl.co.uk>
Date: Tue, 12 Jul 2022 08:08:42 UTC
I thought this would be easy, but it's not!

I can get the time since the epoch to the nearest second (date +%s), but 
nothing more accurate. This was probably good enough in the 1970s but I 
think it's reasonable to want a better resolution even in a shell script.

Yes, I could write something in 'C' in a few lines of 'C' but I want to 
do this using the base system and nothing else.

Does anyone know of any reasonable trick?

Thanks, Frank.

(P.S. I know GNU has a %N extension to strftime())