字符串做异或使用union
2024-09-27 21:44:11
#include <stdio.h>
#include <sys/time.h>
#include <string.h> union data
{
unsigned char str[];
unsigned long long ll_value[];
unsigned int i_value[];
}; int main(int argc, char **argv)
{
union data a;
union data b;
struct timeval start, end;
int i = ; memset((char *)&a, , );
memset((char *)&b, , ); gettimeofday(&start, NULL);
for (i = ; i < ; i++)
{
a.str[i] = a.str[i] ^ b.str[i];
}
gettimeofday(&end, NULL);
printf("take %dus \n", (int)(((end.tv_sec-start.tv_sec)*+end.tv_usec)-start.tv_usec)); gettimeofday(&start, NULL);
for (i = ; i < ; i++)
{
a.ll_value[i] = a.ll_value[i] ^ b.ll_value[i];
}
gettimeofday(&end, NULL);
printf("take %dus \n", (int)(((end.tv_sec-start.tv_sec)*+end.tv_usec)-start.tv_usec)); gettimeofday(&start, NULL);
for (i = ; i < ; i++)
{
a.i_value[i] = a.i_value[i] ^ b.i_value[i];
}
gettimeofday(&end, NULL);
printf("take %dus \n", (int)(((end.tv_sec-start.tv_sec)*+end.tv_usec)-start.tv_usec)); return 0;
}
take 21us
take 3us
take 5us
最新文章
- Working with Data &#187; Getting started with ASP.NET Core and Entity Framework Core using Visual Studio &#187; 读取关系数据
- Asp.Net Web API 2第十一课——在Web API中使用Dependency Resolver
- 《Programming with Objective-C》
- hdu Largest Rectangle in a Histogram
- SDP学习笔记
- [itint5]任务调度
- EasyUI + Spring MVC + hibernate实现增删改查导入导出
- 『重构--改善既有代码的设计』读书笔记----Introduce Explaning Variable
- DB2 runstats和reorg操作
- Jmeter正则提取器常用的几种方式
- 打印pid,写着玩。
- 【JAVA】pdf转图片
- idea,mybatis读取配置文件报错:Could not find resource configuration.xml
- DP题组
- Mac下nodeJS初体验
- tensoFlow之DNN文本分类
- Styles in Windows Phone
- H5+App开发框架汇总
- DataContract和DataMember的作用
- 洛谷 P1135 奇怪的电梯