Skip to content

@nb /bench-map-deep.php secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<?php
function rawurlencode_deep( $value ) {
if ( is_object( $value ) ) {
foreach( $value as $property => $property_value )
$value->{$property} = rawurlencode_deep( $property_value );
return $value;
} else if ( is_array( $value ) ) {
return array_map( 'rawurlencode_deep', $value );
} else {
return rawurlencode( $value );
}
}
function map_deep( $f, $value ) {
if ( is_object( $value ) ) {
foreach( $value as $property => $property_value )
$value->{$property} = map_deep( $f, $property_value );
return $value;
} else if ( is_array( $value ) ) {
return array_map( $f, $value );
} else {
return $f( $value );
}
}
$string = '9386258903475893052389589037 dfuhlksdfkajshfk shkl sdh#$%^&*(P)FGHJKNGVHJBNKMUYIOGHKJLGHKJL"""""asdjkagshdkjsahd';
$string = (object)array('baba' => 'dyado', 'x' => '123891731231', 'baba' => array( 'x' => 'bababa', 5 => 11), 'super' => 'duper & ? sad"',);
$times = 20000;
var_dump(rawurlencode_deep($string) == map_deep('rawurlencode', $string));
$start = microtime(true);
for($i=0; $i<$times; $i++) {
$s = map_deep('rawurlencode', $string);
}
echo (microtime(true) - $start)."\n";
$start = microtime(true);
for($i=0; $i<$times; $i++) {
$s = rawurlencode_deep($string);
}
echo (microtime(true) - $start)."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.