blake2与md5算法速度对比测试 使用OpenMP优化
2015-11-22 18:48
507 查看
/* Test case for blake2s blake2sp blake2sp_file vs md5 md5_parallel * Result: md5_parallel is fastest. * MD5_File() and MD5_File_Parallel(), see https://github.com/9468305/crsync/blob/master/extra/md5.h */ #include <stdint.h> #include <string.h> #include <stdio.h> #include <time.h> #include <sys/timeb.h> #include "blake2.h" #include "md5.h" #define buflen 8*1024 int tests(const char *filename) { struct timeb start, end; ftime(&start); FILE *file = NULL; if ( (file = fopen(filename, "rb")) == NULL ) { return -1; } uint8_t *buf = malloc(buflen); uint8_t sum[BLAKE2S_OUTBYTES]; blake2s_state S; blake2s_init( &S, BLAKE2S_OUTBYTES ); size_t length = 0; while( 0 != (length = fread(buf, 1, buflen, file)) ) { blake2s_update( &S, ( const uint8_t * )buf, length ); } blake2s_final( &S, sum, BLAKE2S_OUTBYTES ); ftime(&end); double time = (1000.0 * difftime(end.time, start.time) + end.millitm - start.millitm) / 1000; printf("blake2s time = %f seconds\n", time); for(int i=0; i<BLAKE2S_OUTBYTES; i++) printf("%02x", sum[i]); printf("\n"); free(buf); fclose(file); return 0; } int testsp(const char *filename) { struct timeb start, end; ftime(&start); FILE *file = NULL; if ( (file = fopen(filename, "rb")) == NULL ) { return -1; } uint8_t *buf = malloc(buflen); uint8_t sum[BLAKE2S_OUTBYTES]; blake2sp_state S; blake2sp_init( &S, BLAKE2S_OUTBYTES ); size_t length = 0; while( 0 != (length = fread(buf, 1, buflen, file)) ) { blake2sp_update( &S, ( const uint8_t * )buf, length ); } blake2sp_final( &S, sum, BLAKE2S_OUTBYTES ); ftime(&end); double time = (1000.0 * difftime(end.time, start.time) + end.millitm - start.millitm) / 1000; printf("blake2sp time = %f seconds\n", time); for(int i=0; i<BLAKE2S_OUTBYTES; i++) printf("%02x", sum[i]); printf("\n"); free(buf); fclose(file); return 0; } void testblake2sp_file(const char *filename) { struct timeb start, end; ftime(&start); uint8_t sum[BLAKE2S_OUTBYTES]; blake2sp_file(filename, sum, BLAKE2S_OUTBYTES); ftime(&end); double time = (1000.0 * difftime(end.time, start.time) + end.millitm - start.millitm) / 1000; printf("blake2sp_file time = %f seconds\n", time); for(int i=0; i<BLAKE2S_OUTBYTES; i++) printf("%02x", sum[i]); printf("\n"); } void testMD5(const char *filename, int isParallel) { struct timeb start, end; ftime(&start); uint8_t sum[MD5_OUTBYTES]; if(isParallel == 0) MD5_File(filename, sum); else MD5_File_Parallel(filename, sum); ftime(&end); double time = (1000.0 * difftime(end.time, start.time) + end.millitm - start.millitm) / 1000; if(isParallel == 0) printf("md5 time = %f seconds\n", time); else printf("md5p time = %f seconds\n", time); for (int j = 0; j < MD5_OUTBYTES; j++) printf("%02x", sum[j]); printf("\n"); } int main( int argc, char **argv ) { const char *filename = "/sdcard/test.obb"; tests(filename); //testsp(filename); testblake2sp_file(filename); testMD5(filename, 0); testMD5(filename, 1); return 0; }
相关文章推荐
- Linux学习之CentOS系列文档
- Linux内核register_chrdev_region()系列函数
- Linux高级使用功能
- eclipse加载maven工程提示pom.xml无法解析org.apache.maven.plugins:maven-resources-plugin:2.4.3解决方案
- Linux文件权限与文件权限修改
- 推荐几个配色和图标网站
- window,centos双系统坏了
- Windows 8和CentOS 6.4(64)双系统硬盘安装教程
- 31-linux登录mysql
- OpenCV 2.4.11 VS2010 Configuration
- 支付宝手机网站支付私钥公钥生成(window环境)
- 反向代理的概念
- linux 终端下敲ctrl-c时,到底发生了什么?(转)
- openstack用bosh部署cloudfoundry(五)---用bosh部署cloudfoundry
- 在Tomcat环境下使用socket通信
- vs2010配置openGL开发环境
- Nginx配置详解
- getopt 函数 getopt_long函数
- Hadoop2.6.0错误
- Hadoop2.6.0错误