3v4l.org

run code in 300+ PHP versions simultaneously
<?php $numbers = range(32, 127); $numbersLetters = array_map('chr', $numbers); for (;;) { $numbersLetters = array_merge($numbersLetters, $numbersLetters); if (count($numbersLetters) > 1000) { break; } } $numbers = range(1, count($numbersLetters)); printf("Sample size: %d elements in 2 arrays (%d total) \n", count($numbers), count($numbers) + count($numbersLetters)); // =============================------------=============================== printf("Benchmarking speed in foreach + in_array() scenario... (this might take a while) "); shuffle($numbers); shuffle($numbersLetters); $t1 = microtime(true); foreach ($numbers as $number) { if (in_array($number, $numbersLetters)) {} } $t2 = microtime(true); printf("DONE!\n"); printf("Time elapsed: %.5f \n", $t2 - $t1); // =============================------------=============================== printf("Benchmarking speed with array_intersect..."); shuffle($numbers); shuffle($numbersLetters); $t1 = microtime(true); array_intersect($numbers, $numbersLetters); $t2 = microtime(true); printf("DONE!\n"); printf("Time elapsed: %.5f \n", $t2 - $t1);
Output for 7.2.6
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.03764 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00126
Output for 7.2.0
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.04665 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00218
Output for 7.1.10
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.03296 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00123
Output for 7.1.7
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.03834 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00120
Output for 7.1.6
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.10949 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00176
Output for 7.1.5
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05383 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00205
Output for 7.1.4
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05573 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00176
Output for 7.1.3
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05727 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00197
Output for 7.1.2
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05383 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00204
Output for 7.1.1
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.08127 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00264
Output for 7.1.0
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05641 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00208
Output for 7.0.20
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.07595 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00312
Output for 7.0.19
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05316 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00173
Output for 7.0.18
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05348 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00202
Output for 7.0.17
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05402 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00200
Output for 7.0.16
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.06834 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00162
Output for 7.0.15
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05479 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00170
Output for 7.0.14
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05208 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00210
Output for 7.0.13
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05721 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00171
Output for 7.0.12
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.06168 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00164
Output for 7.0.11
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05578 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00258
Output for 7.0.10
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05510 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00195
Output for 7.0.9
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05154 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00162
Output for 7.0.8
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05551 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00162
Output for 7.0.7
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.06634 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00236
Output for 7.0.6
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05207 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00209
Output for 7.0.5
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05573 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00178
Output for 7.0.4
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05435 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00160
Output for 7.0.3
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05545 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00177
Output for 7.0.2
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05408 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00195
Output for 7.0.1
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.07147 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00371
Output for 7.0.0
Sample size: 1536 elements in 2 arrays (3072 total) Benchmarking speed in foreach + in_array() scenario... (this might take a while) DONE! Time elapsed: 0.05263 Benchmarking speed with array_intersect...DONE! Time elapsed: 0.00223

preferences:
83.27 ms | 401 KiB | 37 Q