c++ - 为什么 64 位版本的应用程序比 32 位版本的应用程序慢得多

标签 c++ performance ubuntu 32bit-64bit

为了解决 3G (Ubuntu) 内存问题(有时我们确实需要超过 3G 的内存),我在 64 位环境下编译我的应用程序以使用更多内存。

但是,我的 64 位应用程序比 32 位版本慢得多。

32Bit版本建立在32位机器上; 64 位版本是在 64 位机器上构建的; 在我们的加载测试中,32 位和 64 位版本都在 64 位机器上运行。

我用谷歌搜索,有些人说,不必要的 long 类型会使 64 位比 32 位慢,因为:

man g++:

   -m64
       Generate code for a 32-bit or 64-bit environment.  The 32-bit environment
       sets int, long and pointer to 32 bits and generates code that runs on any
       i386 system. The 64-bit environment sets int to 32 bits and long and
       pointer to 64 bits and generates code for AMD's x86-64 architecture. For
       darwin only the -m64 option turns off the -fno-pic and -mdynamic-no-pic
       options.

所以我将所有的 long 都更改为 int,但结果仍然相同。

请指教。

彼得

编辑:

  • 关于内存,32和64版本使用的内存差不多,大约1.5~ 2.5GB,我的机器有9GB物理内存;
  • 我使用 OProfile 进行分析,对于大多数函数,64 位版本收集 比 32 位版本更多的分析示例;
  • 我想不出任何 其他瓶颈,请指教。
  • 我的应用程序是服务器,加载测试是在 100 个客户端连接下完成的。服务器对来自客户端的音频数据进行大量计算处理。

最佳答案

分析您的应用。这将告诉您慢速代码在哪里。

关于c++ - 为什么 64 位版本的应用程序比 32 位版本的应用程序慢得多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8331660/

相关文章:

c++ - 是return *array;有效的?

linux - 经验丰富的 Windows 开发人员的初学者 Ubuntu Linux 指南

ubuntu - 在 Ubuntu 中设置电子邮件服务器

c++ - 优化此功能(在 C++ 中)

python - 为什么 dict.get(key) 比 dict[key] 运行得慢

mysql - 不搜索字段和进行 %""% 搜索之间的区别

magento - 用于图像的第二个 Linux 服务器(与 Magento 组合)

c++ - 一个全局对象是如何在它被声明为 const 之前构造的?

c++ - Boost date 添加一天,非标准 GMT 字符串

c++ - 用字符串打印出 Vector