Is it better to assign functions like get_the_id() to a variable if it’s used multiple times?

Yes, it is always better to keep the result of a function call in a private variable. But the reason is not performance.

Reliability

In your example, you are calling a function that internally accesses a global variable ($post). A global variable can be overwritten any time, so you might end up with two different post IDs, because some other code changed the variable between your two calls.

Consistency

The function get_the_ID() returns either a positive integer or a boolean (false). That’s terrible, because it forces you to either cast the value to an integer, if you are striving for “ifless” code, or you have to decide what to do after each call again, so you get a lot of repetitive code.

Alternative implementation

I would suggest that you make your functions methods of a class, then pass (or setup) the ID in the constructor and save it internally.
That will reduce the static dependency, and if WordPress ever changes this part, you have only one piece of code to fix.


The performance issue with get_the_ID() is hidden in WP_Post::filter(). But that’s so minor, you can safely ignore it.