3v4l.org

run code in 500+ PHP versions simultaneously
<?php class ArraySliceIterator implements IteratorAggregate { private LimitIterator $backingIterator; public function __construct(array $array, int $offset, int $limit) { $this->backingIterator = new LimitIterator( new ArrayIterator($array), $offset, $limit ); } public function getIterator(): Traversable { return $this->backingIterator; } } function iter_search(mixed $needle, iterable $haystack, bool $strict = false): int|string|false { foreach ( $haystack as $key => $value ) { echo "$key? "; if ( ( $strict && $value === $needle ) || ( ! $strict && $value == $needle ) ) { return $key; } } echo "\nNo more items :("; return false; } $bigArray = range(0, 10_000); $key = iter_search(1066, new ArraySliceIterator($bigArray, 1_000, 100)); echo "\nResult: "; var_dump($key); echo "\n\n----\n\n"; $key = iter_search(1966, new ArraySliceIterator($bigArray, 1_000, 100)); echo "\nResult: "; var_dump($key);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.90.0190.00217.02
8.5.80.0260.00417.09
8.5.70.0230.01017.01
8.5.60.0170.00517.16
8.5.50.0330.01016.71
8.5.40.0240.00816.93
8.5.30.0330.00616.74
8.5.20.0270.00916.89
8.5.10.0240.00616.96
8.5.00.0080.00616.77
8.4.240.0340.00419.73
8.4.230.0200.01019.77
8.4.220.0330.00819.60
8.4.210.0290.01419.51
8.4.200.0340.01219.87
8.4.190.0350.01119.63
8.4.180.0250.00919.63
8.4.170.0370.01019.82
8.4.160.0330.01120.08
8.4.150.0320.00619.82
8.4.140.0310.01117.69
8.4.130.0250.01317.81
8.4.120.0280.00717.94
8.4.110.0200.00517.88
8.4.100.0300.00418.04
8.4.90.0270.00318.03
8.4.80.0230.00517.89
8.4.70.0170.00617.94
8.4.60.0350.01218.14
8.4.50.0380.01118.04
8.4.40.0400.00917.89
8.4.30.0300.00817.63
8.4.20.0180.00418.13
8.4.10.0230.00717.82
8.3.330.0300.00418.63
8.3.320.0150.00618.36
8.3.310.0170.00518.61
8.3.300.0180.00618.68
8.3.290.0140.00718.43
8.3.280.0150.00518.66
8.3.270.0150.00516.70
8.3.260.0180.00416.50
8.3.250.0170.00916.89
8.3.240.0310.00616.74
8.3.230.0210.00616.61
8.3.220.0150.00716.89
8.3.210.0400.01016.90
8.3.200.0330.01016.88
8.3.190.0330.00917.01
8.3.180.0370.00616.95
8.3.170.0360.00916.96
8.3.160.0290.01016.92
8.3.150.0200.00317.09
8.3.140.0150.00516.93
8.3.130.0160.00416.94
8.3.120.0150.00416.96
8.3.110.0180.00317.02
8.3.100.0200.00316.70
8.3.90.0170.00416.93
8.3.80.0310.01217.02
8.3.70.0300.00816.98
8.3.60.0200.00417.14
8.3.50.0160.00616.92
8.3.40.0130.00618.25
8.3.30.0160.00218.41
8.3.20.0140.00518.31
8.3.10.0170.00217.98
8.3.00.0120.00618.23
8.2.330.0270.00218.20
8.2.320.0280.00618.15
8.2.310.0170.00518.05

preferences:
45.67 ms | 866 KiB | 5 Q