127.0.0.1 vs localhost (PHP / MySQL)

Quick benchmark on Windows.

Result:
Time 1.303900
Time 0.811767

<?php
$time = microtime(true);

for ($i=0; $i < 1000; $i++) {
	$con = mysqli_connect("localhost", "root", "");
	mysqli_select_db($con, "mysql");
}

$endtime = microtime(true);

printf("Time %f<br>", $endtime - $time);

$time = microtime(true);
for ($i=0; $i < 1000; $i++) {
	$con = mysqli_connect("127.0.0.1", "root", "");
	mysqli_select_db($con, "mysql");
}

$endtime = microtime(true);

printf("Time %f\n", $endtime - $time);
comments powered by Disqus