Right now I am using:
I want to know if there is a better way for getting the post id that consumes less resources?
An alternative to your way would be to access the
global $post echo $post->ID;
EDIT, pertaining to comments:
--> Needs to be run inside the Loop.
i have tried both options (get_the_ID and accessing $post global) both give me a wrong id.
If the latter is the case, you, or some plugin you are using, has not properly reset postdata.
You say to look elsewhere... where should I be looking?
I have no idea what it is you are writing. But if you experience resource bottlenecks or inefficiency, retrieval of the current post ID is likely not the cause.
You can also use
get_queried_object_id() in conjunction with
is_main_query() outside the Loop
if ( is_main_query() ) $mypostid = get_queried_object_id();
Note that this function will return author id on a archive page, category id on a category archive, etc.