Append this to your ~/.zshrc file.
function preexec() {
timer=$(($(date +%s%0N)/1000000))
}
function precmd() {
if [ $timer ]; then
now=$(($(date +%s%0N)/1000000))
elapsed=$(($now-$timer))
export RPROMPT="%F{cyan}${elapsed}ms %{$reset_color%}"
unset timer
fi
}Remixed from @adri's snippet.

@kimonoki Getting the same error:
bad math expression: operator expected at 'N/1000000'timer=$(($(date +%s%0N)/1000000))- error$(($(date +%s)/1000000))- no errorI am not sure here myself using only
%sinstead of%s%0Ndoes work for me but nanoseconds throws an error...