Fastest hash for non-cryptographic uses?

后端 未结 13 1015
挽巷
挽巷 2020-12-04 08:23

I\'m essentially preparing phrases to be put into the database, they may be malformed so I want to store a short hash of them instead (I will be simply comparing if they exi

相关标签:
13条回答
  • 2020-12-04 08:50

    The implementation for md5 inside hash is a little bit faster than md5(). So this can be an option or some else, please try:

    echo '<pre>';
    
    $run = array();
    
    function test($algo)
    {
      #static $c = 0;
      #if($c>10) return;
      #$c++;
    
     $tss = microtime(true);
     for($i=0; $i<100000; $i++){
      $x = hash($algo, "ana are mere");
     }
     $tse = microtime(true);
    
     $GLOBALS['run'][(string)round($tse-$tss, 5)] = "\nhash({$algo}): \t".round($tse-$tss, 5) . " \t" . $x;
     #echo "\n$i nhash({$algo}): \t".round($tse-$tss, 5) . " \t" . $x;
    }
    array_map('test', hash_algos());
    ksort($run);
    print_r($run);
    echo '</pre>';
    

    You can see at http://www.dozent.net/Tipps-Tricks/PHP/hash-performance

    0 讨论(0)
提交回复
热议问题