There is no performance difference, because the result of get_bloginfo()
comes from an internal cache anyway, because most (all?) of the return values come from get_option()
calls, and these are cached internally with wp_cache_set()
and fetched with wp_cache_get()
. See Exploring the WordPress Cache API.
Even if there would be a difference it would be too small to be relevant.
The more important difference is readability. This is easier to read and less error prone:
$template_dir = get_template_directory_uri();
foreach ( array ( 1, 2, 3 ) as $n )
echo "<img src="https://wordpress.stackexchange.com/questions/107279/$template_dir/data1/images/$n.jpg" alt="">";