There are various ways to get user_ID in WP. But which one is the fastest ? I’ve compared 3 ways

	function get_uid_from_global() {
		global $current_user;
		return $current_user->ID;
	}
	
	function get_uid_by_gcuid() {
		return get_current_user_id();	
	}
	function get_uid_by_wpgcu_id() {
		return wp_get_current_user()->ID;	
	}

Without a doubt, global method was fastest. With multiple 100,000 runs, global method took 0.9~ sec, while wp_get_current_user()->ID method took took 1.3~ sec and get_current_user_id() took 1.5~ sec.

Bir cevap yazın

E-posta hesabınız yayımlanmayacak.