Last active
December 9, 2019 08:05
-
-
Save kagg-design/8ab95d9754cea8e126d2606c361ab59e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'C:\laragon\www\test\wp-load.php'; | |
echo 'Filling up array...' . "\n"; | |
$size = 10 * 1000; | |
$cycles = 1000 * 1000; | |
$array = []; | |
for ( $key = 0; $key < $size; $key ++ ) { | |
$array[ $key ] = wp_rand(); | |
} | |
echo 'Creating object...' . "\n"; | |
$object = (object) $array; | |
echo 'Extracting from array...' . "\n"; | |
ob_start(); | |
$start = microtime( true ); | |
for ( $i = 0; $i < $cycles; $i ++ ) { | |
$key = wp_rand( 0, $size - 1 ); | |
echo $array[ $key ]; | |
} | |
$end = microtime( true ); | |
$array_time = $end - $start; | |
ob_get_clean(); | |
echo 'Extracting from object...' . "\n"; | |
ob_start(); | |
$start = microtime( true ); | |
for ( $i = 0; $i < $cycles; $i ++ ) { | |
$key = wp_rand( 0, $size - 1 ); | |
echo $object->{$key}; | |
} | |
$end = microtime( true ); | |
$object_time = $end - $start; | |
ob_get_clean(); | |
echo 'Array time: ' . number_format( $array_time, 3 ) . " s\n"; | |
echo 'Object time: ' . number_format( $object_time, 3 ) . " s\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment