Skip to content

Instantly share code, notes, and snippets.

@dana-ross
Last active January 6, 2016 17:05
Show Gist options
  • Save dana-ross/c5114ea0f5e18294d32a to your computer and use it in GitHub Desktop.
Save dana-ross/c5114ea0f5e18294d32a to your computer and use it in GitHub Desktop.
function busy_work( $value ) {
$sha256 = partially_apply( 'hash', 'sha256' );
$retval = $value;
for( $i = 0; $i < 1000; $i++ ) {
$retval = $sha256( $retval );
}
return $retval;
}
$memoized_hash = memoize( 'busy_work' );
$hash_value_1 = $memoized_hash( 'sha256', 'Hello World' ); // 0.0058081150054932us
$hash_value_2 = $memoized_hash( 'sha256', 'Hello World' ); // 0.0010941028594971us
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment