为了学术目的,我在 C++ 中使用了基本的数学函数实现。今天,我对以下平方根代码进行了基准测试:
inline float sqrt_new(float n)
{
__asm {
fld n
fsqrt
}
}
Run Code Online (Sandbox Code Playgroud)
我很惊讶地看到它始终比标准sqrt函数快(它需要标准函数执行时间的 85% 左右)。
我不太明白为什么,很想更好地理解它。下面我展示了我用来分析的完整代码(在 Visual Studio 2015 中,在发布模式下编译并打开所有优化):
#include <iostream>
#include <random>
#include <chrono>
#define M 1000000
float ranfloats[M];
using namespace std;
inline float sqrt_new(float n)
{
__asm {
fld n
fsqrt
}
}
int main()
{
default_random_engine randomGenerator(time(0));
uniform_real_distribution<float> diceroll(0.0f , 1.0f);
chrono::high_resolution_clock::time_point start1, start2;
chrono::high_resolution_clock::time_point end1, end2;
float sqrt1 = 0;
float sqrt2 = 0;
for (int i = 0; i<M; …Run Code Online (Sandbox Code Playgroud) 我知道 Emacs 有允许在 RMarkdown 中编码的 polymode 包。然而,似乎 Spacemacs 仍然缺少相当于多模层的东西。
我一直在尝试将它直接安装到 Spacemacs 中,但没有成功。因此我的问题是:有没有办法在 Spacemacs(不是普通的 Emacs)中编辑 RMarkdown 文件。