Skip to content

Conversation

@stloyd
Copy link
Member

@stloyd stloyd commented Oct 7, 2023

Change Log

Added

Fixed

Changed

  • Optimize `DropDuplicatesTransformer` hashing

Removed

Deprecated

Security


Description

@norberttech
Copy link
Member

For a reference: https://gist.github.com/alcaeus/536156663fac96744eba77b3e133e50a?permalink_comment_id=4031242#gistcomment-4031242

Additional simplified benchmark code:

<?php

// Initialize test array and key-value
$arraySize = 100000;
$testArrayInArray = [];
$testArrayIsset = [];

for ($i = 0; $i < $arraySize; $i++) {
    $testArrayInArray[] = $i . '_value';
    $testArrayIsset[$i  . '_value'] = true;
}


// Benchmark for in_array()
$start_time_in_array = microtime(true);

for ($i = 0; $i < 10000; $i++) {
    $randomValue = random_int(0, $arraySize - 1) . '_value';
    $result = \in_array($randomValue, $testArrayInArray);
}

$end_time_in_array = microtime(true);
$execution_time_in_array = $end_time_in_array - $start_time_in_array;

// Benchmark for isset()
$start_time_isset = microtime(true);

for ($i = 0; $i < 10000; $i++) {
    $randomValue = random_int(0, $arraySize - 1) . '_value';
    $result = isset($testArray[$randomValue]);
}

$end_time_isset = microtime(true);
$execution_time_isset = $end_time_isset - $start_time_isset;

// Output the results
echo "Time taken by in_array: " . $execution_time_in_array . " seconds" . PHP_EOL;
echo "Time taken by isset: " . $execution_time_isset . " seconds" . PHP_EOL;

Time taken by in_array: 6.7433869838715 seconds
Time taken by isset: 0.0020461082458496 seconds

@norberttech norberttech merged commit c6ced02 into flow-php:1.x Oct 7, 2023
@stloyd stloyd deleted the duplicates-optim branch October 7, 2023 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants