小编sma*_*rne的帖子

性能交换整数与双倍

出于某种原因,我的代码能够比双整数更快地执行双向交换.我不知道为什么会发生这种情况.

在我的机器上,双交换循环比整数交换循环快11倍.双打/整数的哪些属性使它们以这种方式执行?

测试设置

  • Visual Studio 2012 x64
  • cpu core i7 950
  • 构建为Release并直接运行exe,VS Debug挂钩事物

输出:

Process time for ints 1.438 secs

Process time for doubles 0.125 secs

#include <iostream>
#include <ctime>
using namespace std;

#define N 2000000000

void swap_i(int *x, int *y) {
    int tmp = *x;
    *x = *y;
    *y = tmp;
}

void swap_d(double *x, double *y) {
    double tmp = *x;
    *x = *y;
    *y = tmp;
}

int main () {
    int a = 1, b = …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-optimization

7
推荐指数
1
解决办法
245
查看次数

使用LINQ to XML解析深层嵌套属性时遇到问题

我一直试图在c#中解析这个xml

<schema uri=http://blah.com/schema >
   <itemGroups>
     <itemGroup description="itemGroup1 label="itemGroup1">
       <items>
        <item description="The best" itemId="1" label="Nutella"/>
        <item description="The worst" itemId="2" label="Vegemite"/>
       </items>
     </itemGroup>
   </itemGroups>
</schema>

\itemGroup1\Nutella-The best
\itemGroup1\Vegemite-The worst
Run Code Online (Sandbox Code Playgroud)

任何帮助或方向将不胜感激.

c# xml linq-to-xml

2
推荐指数
1
解决办法
759
查看次数

标签 统计

c# ×1

c++ ×1

compiler-optimization ×1

linq-to-xml ×1

xml ×1