I did a test with a 100K loop on each and yours is actually fatesr by .001 to .005 seconds. I did another test where I removed the unset out of mine and my was .040 .042 seconds fatesr. Here’s my test code:<?php$time_start = microtime(true);$i =0;do { $a = 1; $b = 2; list($a, $b) = array($b, $a); }while(++$i < 100000);$time_end = microtime(true);$time = $time_end $time_start;echo Test 1: ,$time, ;$time_start = microtime(true);$i =0;do { $a = 1; $b = 2; $x = $a; $y = $b; $a = $y; $b = $x; unset($x, $y); }while(++$i < 100000);$time_end = microtime(true);$time = $time_end $time_start;echo Test 2: ,$time, ;$time_start = microtime(true);$i =0;do { $a = 1; $b = 2; $x = $a; $y = $b; $a = $y; $b = $x; }while(++$i < 100000);$time_end = microtime(true);$time = $time_end $time_start;echo Test 3: ,$time, ;
I did a test with a 100K loop on each and yours is actually fatesr by .001 to .005 seconds. I did another test where I removed the unset out of mine and my was .040 .042 seconds fatesr. Here’s my test code:<?php$time_start = microtime(true);$i =0;do { $a = 1; $b = 2; list($a, $b) = array($b, $a); }while(++$i < 100000);$time_end = microtime(true);$time = $time_end $time_start;echo Test 1: ,$time, ;$time_start = microtime(true);$i =0;do { $a = 1; $b = 2; $x = $a; $y = $b; $a = $y; $b = $x; unset($x, $y); }while(++$i < 100000);$time_end = microtime(true);$time = $time_end $time_start;echo Test 2: ,$time, ;$time_start = microtime(true);$i =0;do { $a = 1; $b = 2; $x = $a; $y = $b; $a = $y; $b = $x; }while(++$i < 100000);$time_end = microtime(true);$time = $time_end $time_start;echo Test 3: ,$time, ;