我使用vs2012并想测试SSE和AVX的效率.SSE和AVX的代码几乎相同,只是SSE使用_m128而AVX使用_m256.我期望AVX代码比SSE代码快两倍,但测试结果显示它们的速度几乎相同.
我尝试选择/ arch:AVX或/ arch:SSE或/ NOT SET并注释SSE代码或注释AVX代码,无论我测试什么,SSE代码使用的时间约为2138ms,AVX代码约为2106ms.外部for循环仅用于增加循环时间,
#include "testfun.h"
#include <iostream>
#include <time.h>
#include <malloc.h>
#include "immintrin.h"
using namespace std;
#define dataLen 800000
void testfun()
{
float *buf1 = reinterpret_cast<float*>(_aligned_malloc( sizeof(float)*dataLen, 32 ));
float *buf2 = reinterpret_cast<float*>(_aligned_malloc( sizeof(float)*dataLen, 32 ));
for(int i=0; i<dataLen; i++)
{
buf1[i] = 1;
buf2[i] = 1;
}
double timePassed;
int t = clock();
float sum = 0;
//=========================SSE CODE=====================================
__m128 *p1 = (__m128 *)buf1;
__m128 *p2 = (__m128 *)buf2;
__m128 _result = _mm_set_ps1(0.0f);
for(int j=0;j<10000; j++) …Run Code Online (Sandbox Code Playgroud) #include
int main(void)
{
char str[100]="88888888888888";
char t[20]="";
gets(t);
puts(str);
puts(t);
return 0;
}Run Code Online (Sandbox Code Playgroud)

第一行
555555555555555555555555555555555
Run Code Online (Sandbox Code Playgroud)
投入.
为什么str是55555555555?为什么str不88888888888888888和55555555555588888?
错误:请求成员`st_mode'不是结构或联合
错误:')'标记之前的语法错误
错误:`read'的参数1的不兼容类型
/* Here is the code */
int main( int argc, char **argv)
{
int src, dst;
char buf[BUFSIZE];
int n;
if (argc!=3)
{
printf("\n usage: copy src dst\n");
return -1;
}
struct stat src;
if(stat(argv[1],&src) < 0)
return 1;
printf("File Permissions for source file: \t");
printf("%d", S_ISDIR(src.st_mode)) ? "d" : "-");
printf(src.st_mode & S_IRUSR) ? "r" : "-");
printf(src.st_mode & S_IWUSR) ? "w" : "-");
printf(src.st_mode & S_IXUSR) ? "x" : "-");
int creat(char *dst,int perms);
printf("File …Run Code Online (Sandbox Code Playgroud) 每次我写C++,我都需要把不同的代码放到main中,有没有办法让它变得简单,就像a1.cpp有main,a2.cpp有另一个main,比如a1.cpp
int main() {
printf("a1");
}
Run Code Online (Sandbox Code Playgroud)
在a2.cpp
int main() {
printf("a2");
}
Run Code Online (Sandbox Code Playgroud)
当你运行a1.cpp时你得到a1打印输出,当你运行时a2,你得到字符串a2,我该怎么办呢?