PHP Classes

File: benchmark_array_merge_vs_plus.php

Recommend this page to a friend!
  Classes of Jorge Castro   PHP Benchmarks   benchmark_array_merge_vs_plus.php   Download  
File: benchmark_array_merge_vs_plus.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Benchmarks
Evaluate the speed of PHP running different tasks
Author: By
Last change:
Date: 3 years ago
Size: 1,039 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
/** @noinspection AutoloadingIssuesInspection */


$numbers = range(0, 1000);

include
"Collection.php";

$instances=100000;

$exist=true;

$array1=['repeated'=>'abc','b'=>'bcd','c'=>'def',20,30,40];
$array2=['repeated'=>'abc','d'=>'abc2','e'=>'bcd2','f'=>'def2',50,60,70];


// **********************************************************************************
$t1=microtime(true);
for(
$i=0;$i<$instances;$i++) {
   
$r=array_merge($array1,$array2);
}
$t2=microtime(true);
$table['array_merge']=$t2-$t1;
// **********************************************************************************
$t1=microtime(true);
for(
$i=0;$i<$instances;$i++) {
   
$r=array_replace($array1,$array2);
}
$t2=microtime(true);
$table['array_replace']=$t2-$t1;
// **********************************************************************************
$t1=microtime(true);
for(
$i=0;$i<$instances;$i++) {
   
$r= $array1 + $array2;
}
$t2=microtime(true);
$table['plus']=$t2-$t1;


echo \
mapache_commons\Collection::generateTable($table);