惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Last Week in AI
Last Week in AI
IT之家
IT之家
A
About on SuperTechFans
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
V
Visual Studio Blog
Microsoft Security Blog
Microsoft Security Blog
博客园_首页
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
Vercel News
Vercel News
博客园 - Franky
有赞技术团队
有赞技术团队
B
Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
量子位
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog

博客园 - Len3d

Audacity录音+混响初步经验 专辑歌曲列表 奇迹 找到你 下弦月 研报和信息查询网站 研报查询链接 初步测试了一下C++11的async/future 徒手画个disk不容易啊。。。 fast powf Mongoose也是个大坑 A tiny program to benchmark image transpose algorithms On extracting ops from LLVM backend Into concurrent LRU caching once again 性能大坑 多项式在线拟合神器 iOS app开发资料整理 完美的视图旋转算法 Windows上使用clang编译 nodejs Rpath handling on Linux C++ Web Service SDK Fast integer math tricks for C Point in polygon algorithm C code
SSE sqrt还是比C math库的sqrtf快了不少
Len3d · 2017-11-28 · via 博客园 - Len3d
#include <stdio.h>
#include <xmmintrin.h>
#define NOMINMAX
#include <windows.h>
#include <math.h>
#include <time.h>

__forceinline float fast_sqrt(float x)
{
    return _mm_cvtss_f32(_mm_sqrt_ss(_mm_set_ss(x)));
}

int main(int argc, char *argv[])
{
    const int N = 100000000;
    float *buf = new float[N];
    for (int i = 0; i < N; ++i)
    {
        buf[i] = 1000.0f * (float)rand() / (float)RAND_MAX;
    }

    float sum;
    int start_time;

    sum = 0.0f;
    start_time = clock();
    for (int i = 0; i < N; ++i)
    {
        sum += sqrtf(buf[i]);
    }
    printf("sum = %f   in clock %d\n", sum, clock() - start_time);



    sum = 0.0f;
    start_time = clock();
    for (int i = 0; i < N; ++i)
    {
        sum += fast_sqrt(buf[i]);
    }
    printf("sum (fast) = %f   in clock %d\n", sum, clock() - start_time);



    delete[]buf;
    return 0;
}

测试结果:

sum = 536870912.000000 in clock 391
sum (fast) = 536870912.000000 in clock 281