Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bubble script for testing speed of PHP-8
<?php
function bubble_sort($array)
{
$start = microtime(true);
do
{
$sw = false;
for($i = 0, $size = count($array) - 1; $i < $size; $i++)
{
if( $array[$i] > $array[$i + 1] )
{
list( $array[$i + 1], $array[$i] ) =
array($array[$i], $array[$i + 1]);
$sw = true;
}
}
}
while($sw);
$end = microtime(true);
return $end - $start;
}
$array = array(1000, -202, 3, 0, 2, 77, 5, -1, 4, 34, -203, 1, 0.5 , -3, 0.88,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,
4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,
5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,
6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,
39000, 444, 0.99, -44, 4, 53, -4, 23, -201,
309900, 444, 0.99, 23, 123, 453, -4, 23, -201,
309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,
309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,
30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,
-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,
3000, 424, 0.19, -44, 4, 453, -4, 23, -21,
300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,
301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,
3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -2010000
);
echo "\n";
echo bubble_sort($array);
echo "\n";
?>
@PedroEscudero

This comment has been minimized.

Copy link
Owner Author

@PedroEscudero PedroEscudero commented Feb 19, 2020

This Gist is for the following article published in Medium:

https://levelup.gitconnected.com/how-fast-is-php-8-going-to-be-f7fdc111cd6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment