Skip to content

Instantly share code, notes, and snippets.

@kagg-design
Last active December 9, 2019 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagg-design/8ab95d9754cea8e126d2606c361ab59e to your computer and use it in GitHub Desktop.
Save kagg-design/8ab95d9754cea8e126d2606c361ab59e to your computer and use it in GitHub Desktop.
<?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