3v4l.org

run code in 300+ PHP versions simultaneously
<?php function noSort($a, $b) { $result = []; foreach ($a as $v) { $index = array_search($v, $b); if ($index !== false) { $result[] = $v; unset($b[$index]); } } return $result; } function intersectSimpler(...$twoArrays) { $result = []; sort($twoArrays); foreach ($twoArrays[0] as $v) { $index = array_search($v, $twoArrays[1]); if ($index !== false) { $result[] = $v; unset($twoArrays[1][$index]); } } return $result; } function intersectSimplest($a, $b): array { $result = []; if (count($a) < count($b)) { $short = $a; $long = $b; } else { $short = $b; $long = $a; } foreach ($short as $v) { $index = array_search($v, $long); if ($index !== false) { $result[] = $v; unset($long[$index]); } } return $result; } function intersectSimplish($a, $b): array { $result = []; if (count($a) < count($b)) { $short = $a; $long = $b; } else { $short = $b; $long = $a; } foreach ($short as $v) { if (in_array($v, $long)) { $result[] = $v; unset($long[array_search($v, $long)]); } } return $result; } function intersectSimple($a, $b) { $result = array(); $short = count($a) < count($b) ? $a : $b; $long = count($a) < count($b) ? $b : $a; foreach ($short as $v) { if (in_array($v, $long)) { //if found add to results and remove from b $result[] = $v; unset($long[array_search($v, $long)]); } } return $result; } function intersectAderrahim($a, $b) { $a_values_count = array_count_values($a); $b_values_count = array_count_values($b); $res = array_values(array_intersect($a, $b)); $res_values_count = array_count_values($res); foreach ($res as $key => $val) { if ($res_values_count[$val] > $a_values_count[$val] || $res_values_count[$val] > $b_values_count[$val]) { unset($res[$key]); $res_values_count[$val]--; } } return array_values($res); } //Start timer $start = microtime(true); echo "Start Test\n"; //Run code 100000 times for ($i = 0; $i < 100000; $i++) { $a = [1, 1, 1, 1, 2, 3, 4, 4, 5, 6, 8, 8, 8]; $b = [1, 1, 3, 3, 5, 5, 5, 6, 7, 9, 9]; $result = intersectAderrahim($a, $b); } //Stop timer $end = microtime(true); $time = $end - $start; //Print performance in microseconds echo "Performance Aderrahim: $time\n"; //Start timer $start = microtime(true); echo "Start Test\n"; //Run code 100000 times for ($i = 0; $i < 100000; $i++) { $a = [1, 1, 1, 1, 2, 3, 4, 4, 5, 6, 8, 8, 8]; $b = [1, 1, 3, 3, 5, 5, 5, 6, 7, 9, 9]; $result = noSort($a, $b); } //Stop timer $end = microtime(true); $time = $end - $start; //Print performance in microseconds echo "Performance NoSort: $time\n"; //Start timer $start = microtime(true); echo "Start Test\n"; //Run code 100000 times for ($i = 0; $i < 100000; $i++) { $a = [1, 1, 1, 1, 2, 3, 4, 4, 5, 6, 8, 8, 8]; $b = [1, 1, 3, 3, 5, 5, 5, 6, 7, 9, 9]; $result = intersectSimpler($a, $b); } //Stop timer $end = microtime(true); $time = $end - $start; //Print performance in microseconds echo "Performance Simpler: $time\n"; //Start timer $start = microtime(true); echo "Start Test\n"; //Run code 100000 times for ($i = 0; $i < 100000; $i++) { $a = [1, 1, 1, 1, 2, 3, 4, 4, 5, 6, 8, 8, 8]; $b = [1, 1, 3, 3, 5, 5, 5, 6, 7, 9, 9]; $result = intersectSimplish($a, $b); } //Stop timer $end = microtime(true); $time = $end - $start; //Print performance in microseconds echo "Performance Simplish: $time\n"; //Start timer $start = microtime(true); echo "Start Test\n"; //Run code 100000 times for ($i = 0; $i < 100000; $i++) { $a = [1, 1, 1, 1, 2, 3, 4, 4, 5, 6, 8, 8, 8]; $b = [1, 1, 3, 3, 5, 5, 5, 6, 7, 9, 9]; $result = intersectSimplest($a, $b); } //Stop timer $end = microtime(true); $time = $end - $start; //Print performance in microseconds echo "Performance Simplest: $time\n"; //Start timer $start = microtime(true); echo "Start Test\n"; //Run code 100000 times for ($i = 0; $i < 100000; $i++) { $a = [1, 1, 1, 1, 2, 3, 4, 4, 5, 6, 8, 8, 8]; $b = [1, 1, 3, 3, 5, 5, 5, 6, 7, 9, 9]; $result = intersectSimple($a, $b); } //Stop timer $end = microtime(true); $time = $end - $start; //Print performance in microseconds echo "Performance Simple: $time\n";
Output for 8.2.0
Start Test Performance Aderrahim: 0.1749050617218 Start Test Performance NoSort: 0.060549974441528 Start Test Performance Simpler: 0.081342935562134 Start Test Performance Simplish: 0.06725001335144 Start Test Performance Simplest: 0.061482906341553 Start Test Performance Simple: 0.067451953887939
Output for 8.1.13
Start Test Performance Aderrahim: 0.17982196807861 Start Test Performance NoSort: 0.063269138336182 Start Test Performance Simpler: 0.082894086837769 Start Test Performance Simplish: 0.073304891586304 Start Test Performance Simplest: 0.061497926712036 Start Test Performance Simple: 0.071119070053101
Output for 8.1.12
Start Test Performance Aderrahim: 0.17630410194397 Start Test Performance NoSort: 0.066442966461182 Start Test Performance Simpler: 0.080931901931763 Start Test Performance Simplish: 0.074100017547607 Start Test Performance Simplest: 0.064985036849976 Start Test Performance Simple: 0.07437801361084
Output for 8.1.11
Start Test Performance Aderrahim: 0.18461680412292 Start Test Performance NoSort: 0.067609786987305 Start Test Performance Simpler: 0.084722995758057 Start Test Performance Simplish: 0.070536136627197 Start Test Performance Simplest: 0.062483072280884 Start Test Performance Simple: 0.071472883224487
Output for 8.1.10
Start Test Performance Aderrahim: 0.18083596229553 Start Test Performance NoSort: 0.070365190505981 Start Test Performance Simpler: 0.084542036056519 Start Test Performance Simplish: 0.070371866226196 Start Test Performance Simplest: 0.068269014358521 Start Test Performance Simple: 0.070327043533325
Output for 8.1.9
Start Test Performance Aderrahim: 0.18322801589966 Start Test Performance NoSort: 0.067539930343628 Start Test Performance Simpler: 0.08240795135498 Start Test Performance Simplish: 0.072616815567017 Start Test Performance Simplest: 0.064154863357544 Start Test Performance Simple: 0.074952840805054
Output for 8.1.8
Start Test Performance Aderrahim: 0.17674994468689 Start Test Performance NoSort: 0.059515953063965 Start Test Performance Simpler: 0.084357023239136 Start Test Performance Simplish: 0.069676876068115 Start Test Performance Simplest: 0.059716939926147 Start Test Performance Simple: 0.06951904296875
Output for 8.1.7
Start Test Performance Aderrahim: 0.17537188529968 Start Test Performance NoSort: 0.066309928894043 Start Test Performance Simpler: 0.083402872085571 Start Test Performance Simplish: 0.069133043289185 Start Test Performance Simplest: 0.063341856002808 Start Test Performance Simple: 0.07249903678894
Output for 8.1.6
Start Test Performance Aderrahim: 0.18549180030823 Start Test Performance NoSort: 0.06654691696167 Start Test Performance Simpler: 0.083724021911621 Start Test Performance Simplish: 0.068161010742188 Start Test Performance Simplest: 0.06220006942749 Start Test Performance Simple: 0.070528984069824
Output for 8.1.5
Start Test Performance Aderrahim: 0.17944192886353 Start Test Performance NoSort: 0.067474126815796 Start Test Performance Simpler: 0.084756851196289 Start Test Performance Simplish: 0.073815822601318 Start Test Performance Simplest: 0.065352916717529 Start Test Performance Simple: 0.074579000473022
Output for 8.1.4
Start Test Performance Aderrahim: 0.18396806716919 Start Test Performance NoSort: 0.068861961364746 Start Test Performance Simpler: 0.086169958114624 Start Test Performance Simplish: 0.077088117599487 Start Test Performance Simplest: 0.06519889831543 Start Test Performance Simple: 0.070772886276245
Output for 8.1.3
Start Test Performance Aderrahim: 0.17924284934998 Start Test Performance NoSort: 0.06529712677002 Start Test Performance Simpler: 0.081295013427734 Start Test Performance Simplish: 0.069528102874756 Start Test Performance Simplest: 0.063355207443237 Start Test Performance Simple: 0.068221092224121
Output for 8.1.2
Start Test Performance Aderrahim: 0.17451214790344 Start Test Performance NoSort: 0.066851139068604 Start Test Performance Simpler: 0.080510139465332 Start Test Performance Simplish: 0.066341876983643 Start Test Performance Simplest: 0.063703060150146 Start Test Performance Simple: 0.069191932678223
Output for 8.1.1
Start Test Performance Aderrahim: 0.18574500083923 Start Test Performance NoSort: 0.068850040435791 Start Test Performance Simpler: 0.085855007171631 Start Test Performance Simplish: 0.070600986480713 Start Test Performance Simplest: 0.065921068191528 Start Test Performance Simple: 0.070971965789795
Output for 8.1.0
Start Test Performance Aderrahim: 0.18247294425964 Start Test Performance NoSort: 0.072827100753784 Start Test Performance Simpler: 0.084532022476196 Start Test Performance Simplish: 0.074905157089233 Start Test Performance Simplest: 0.066528797149658 Start Test Performance Simple: 0.069668054580688
Output for 8.0.26
Start Test Performance Aderrahim: 0.17782092094421 Start Test Performance NoSort: 0.067157030105591 Start Test Performance Simpler: 0.079035997390747 Start Test Performance Simplish: 0.07419490814209 Start Test Performance Simplest: 0.062563896179199 Start Test Performance Simple: 0.074892997741699
Output for 8.0.25
Start Test Performance Aderrahim: 0.18089890480042 Start Test Performance NoSort: 0.067572116851807 Start Test Performance Simpler: 0.082733154296875 Start Test Performance Simplish: 0.073989152908325 Start Test Performance Simplest: 0.064479112625122 Start Test Performance Simple: 0.074702978134155
Output for 8.0.24
Start Test Performance Aderrahim: 0.18349409103394 Start Test Performance NoSort: 0.067383050918579 Start Test Performance Simpler: 0.080610036849976 Start Test Performance Simplish: 0.075850009918213 Start Test Performance Simplest: 0.065323114395142 Start Test Performance Simple: 0.075545072555542
Output for 8.0.23
Start Test Performance Aderrahim: 0.18175315856934 Start Test Performance NoSort: 0.069981098175049 Start Test Performance Simpler: 0.086318016052246 Start Test Performance Simplish: 0.076513051986694 Start Test Performance Simplest: 0.067340135574341 Start Test Performance Simple: 0.077842950820923
Output for 8.0.22
Start Test Performance Aderrahim: 0.17444515228271 Start Test Performance NoSort: 0.068408966064453 Start Test Performance Simpler: 0.083227872848511 Start Test Performance Simplish: 0.073684930801392 Start Test Performance Simplest: 0.065272808074951 Start Test Performance Simple: 0.074712991714478
Output for 8.0.21
Start Test Performance Aderrahim: 0.1838641166687 Start Test Performance NoSort: 0.070167064666748 Start Test Performance Simpler: 0.089949131011963 Start Test Performance Simplish: 0.074939966201782 Start Test Performance Simplest: 0.067389965057373 Start Test Performance Simple: 0.076288938522339
Output for 8.0.20
Start Test Performance Aderrahim: 0.18386602401733 Start Test Performance NoSort: 0.069161891937256 Start Test Performance Simpler: 0.086359024047852 Start Test Performance Simplish: 0.07020902633667 Start Test Performance Simplest: 0.06502890586853 Start Test Performance Simple: 0.070223093032837
Output for 8.0.19
Start Test Performance Aderrahim: 0.17817497253418 Start Test Performance NoSort: 0.068033933639526 Start Test Performance Simpler: 0.08473014831543 Start Test Performance Simplish: 0.075466156005859 Start Test Performance Simplest: 0.066754102706909 Start Test Performance Simple: 0.076930046081543
Output for 8.0.18
Start Test Performance Aderrahim: 0.18248605728149 Start Test Performance NoSort: 0.069494009017944 Start Test Performance Simpler: 0.088281154632568 Start Test Performance Simplish: 0.074491024017334 Start Test Performance Simplest: 0.068104028701782 Start Test Performance Simple: 0.075434923171997
Output for 8.0.17
Start Test Performance Aderrahim: 0.18249297142029 Start Test Performance NoSort: 0.068819046020508 Start Test Performance Simpler: 0.086605787277222 Start Test Performance Simplish: 0.071742057800293 Start Test Performance Simplest: 0.066622018814087 Start Test Performance Simple: 0.071735143661499
Output for 8.0.16
Start Test Performance Aderrahim: 0.17666888237 Start Test Performance NoSort: 0.067161083221436 Start Test Performance Simpler: 0.083775997161865 Start Test Performance Simplish: 0.074559211730957 Start Test Performance Simplest: 0.062543153762817 Start Test Performance Simple: 0.075114011764526
Output for 8.0.15
Start Test Performance Aderrahim: 0.18744111061096 Start Test Performance NoSort: 0.066154003143311 Start Test Performance Simpler: 0.092350006103516 Start Test Performance Simplish: 0.076858997344971 Start Test Performance Simplest: 0.067898035049438 Start Test Performance Simple: 0.0836501121521
Output for 8.0.14
Start Test Performance Aderrahim: 0.1914119720459 Start Test Performance NoSort: 0.070512056350708 Start Test Performance Simpler: 0.089887857437134 Start Test Performance Simplish: 0.079722166061401 Start Test Performance Simplest: 0.078015089035034 Start Test Performance Simple: 0.075645923614502
Output for 8.0.13
Start Test Performance Aderrahim: 0.18533802032471 Start Test Performance NoSort: 0.066927909851074 Start Test Performance Simpler: 0.088479995727539 Start Test Performance Simplish: 0.074491024017334 Start Test Performance Simplest: 0.065208911895752 Start Test Performance Simple: 0.07355785369873
Output for 8.0.12
Start Test Performance Aderrahim: 0.18588805198669 Start Test Performance NoSort: 0.064351081848145 Start Test Performance Simpler: 0.085861921310425 Start Test Performance Simplish: 0.069566965103149 Start Test Performance Simplest: 0.065054893493652 Start Test Performance Simple: 0.070034980773926
Output for 8.0.11
Start Test Performance Aderrahim: 0.18249011039734 Start Test Performance NoSort: 0.065464973449707 Start Test Performance Simpler: 0.089024782180786 Start Test Performance Simplish: 0.076256036758423 Start Test Performance Simplest: 0.065302133560181 Start Test Performance Simple: 0.076092958450317
Output for 8.0.10
Start Test Performance Aderrahim: 0.17917084693909 Start Test Performance NoSort: 0.071222066879272 Start Test Performance Simpler: 0.090598106384277 Start Test Performance Simplish: 0.076549053192139 Start Test Performance Simplest: 0.070904970169067 Start Test Performance Simple: 0.077301979064941
Output for 8.0.9
Start Test Performance Aderrahim: 0.18404293060303 Start Test Performance NoSort: 0.06406307220459 Start Test Performance Simpler: 0.085145950317383 Start Test Performance Simplish: 0.070650100708008 Start Test Performance Simplest: 0.061792135238647 Start Test Performance Simple: 0.06996488571167
Output for 8.0.8
Start Test Performance Aderrahim: 0.17760801315308 Start Test Performance NoSort: 0.063539981842041 Start Test Performance Simpler: 0.084723949432373 Start Test Performance Simplish: 0.070878028869629 Start Test Performance Simplest: 0.06315803527832 Start Test Performance Simple: 0.072397947311401
Output for 8.0.7
Start Test Performance Aderrahim: 0.18227577209473 Start Test Performance NoSort: 0.066134929656982 Start Test Performance Simpler: 0.086979866027832 Start Test Performance Simplish: 0.07719898223877 Start Test Performance Simplest: 0.069261074066162 Start Test Performance Simple: 0.077224016189575
Output for 8.0.6
Start Test Performance Aderrahim: 0.1809720993042 Start Test Performance NoSort: 0.063647031784058 Start Test Performance Simpler: 0.081067800521851 Start Test Performance Simplish: 0.073606014251709 Start Test Performance Simplest: 0.062469005584717 Start Test Performance Simple: 0.074291944503784
Output for 8.0.5
Start Test Performance Aderrahim: 0.17940616607666 Start Test Performance NoSort: 0.066670894622803 Start Test Performance Simpler: 0.082731962203979 Start Test Performance Simplish: 0.077116966247559 Start Test Performance Simplest: 0.064489126205444 Start Test Performance Simple: 0.075712919235229
Output for 8.0.3
Start Test Performance Aderrahim: 0.18056797981262 Start Test Performance NoSort: 0.06699800491333 Start Test Performance Simpler: 0.087394952774048 Start Test Performance Simplish: 0.074664115905762 Start Test Performance Simplest: 0.06578803062439 Start Test Performance Simple: 0.074760913848877
Output for 8.0.2
Start Test Performance Aderrahim: 0.1785900592804 Start Test Performance NoSort: 0.066874980926514 Start Test Performance Simpler: 0.089898109436035 Start Test Performance Simplish: 0.075105905532837 Start Test Performance Simplest: 0.066222906112671 Start Test Performance Simple: 0.07613205909729
Output for 8.0.1
Start Test Performance Aderrahim: 0.18173313140869 Start Test Performance NoSort: 0.06509804725647 Start Test Performance Simpler: 0.082746982574463 Start Test Performance Simplish: 0.073324203491211 Start Test Performance Simplest: 0.064342975616455 Start Test Performance Simple: 0.074501991271973

preferences:
67.78 ms | 472 KiB | 5 Q