文件上传要做哈希,当然是越快越好,文件哈希有sha1_file与md5_file。 哪个更快呢?网上也没搜到相关的文章,于是决定做一个小测试: 测试代码如下: //哈希效率function microtime_float(){ list($usec, $sec) = explode( , microtime()); return ((float)$
文件上传要做哈希,当然是越快越好,文件哈希有sha1_file与md5_file。
哪个更快呢?网上也没搜到相关的文章,于是决定做一个小测试:
测试代码如下:
//哈希效率 function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $timeS = microtime_float(); //$file = __file__; $file = "E:\master.zip"; //$i = 100000; $i = 100; while($i--){ //$h = sha1_file($file); $h = md5_file($file); } usleep(100); $timeE = microtime_float(); echo ($timeE-$timeS);
这个脚本得到如下结果:
百万次1k大小文件
--------------------------------------------------------------------------------------------------------------------------------------------------------
m:16.13895215988216.40040507316616.78716578483616.40980591774 17.104665184021
百次10M大小文件
---------------------------------------------------------------------------------------------------------------------------------------------------------
s:11.08235087394710.25670900344812.99189391136210.37381591796911.834413194656
m:7.15002002716067.49447097778327.97997798919687.04725685119638.2962888717651
测试环境为64位win7 E5400 8G php5.2.17
看来,在这个环境下,MD5还是更快一点的。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
