调试符号会影响 Rust 的性能吗?

编程入门 行业动态 更新时间:2024-10-28 07:20:01
本文介绍了调试符号会影响 Rust 的性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在运行使用调试符号编译的 Rust 实用程序.

I'm running Rust utilities that compiled with debug symbols.

cargo build # without the "--release" flag

与用 C 编写的相同实用程序相比,这些真的很慢.

These are really slow compared to the same utilities written in C.

调试符号是否有可能影响性能?

Is it possible that the debug symbols affected the performance?

推荐答案

回答你的问题

使用调试符号进行编译通常会使您的二进制文件在 Linux 和类 UNIX 平台上变大.这可能意味着您需要从磁盘加载更多数据,这会影响性能.应该没有任何运行时差异.

Answering your question

Compiling with debug symbols will usually make your binary larger on Linux and UNIX-like platforms. This may mean that you need to load more data from disk, which can affect performance. There shouldn't really be any runtime difference.

您可以将调试信息拆分为单独的文件,以避免增加二进制文件的大小.Windows 默认使用 PDB 文件执行此操作,macOS 默认使用 dSYM 文件执行此操作.

You can split the debugging information into separate files to avoid increasing the size of your binaries. Windows does this by default with PDB files and macOS does this by default with dSYM files.

另见:

  • 调试符号如何影响 GCC 编译的 Linux 可执行文件的性能?

如果你不使用 --release 编译,你的代码会变慢.如果要判断性能,请使用 --release 编译.

If you don't compile with --release, your code will be slower. Compile with --release if you are judging performance.

在调试模式和发布模式之间切换可以改变的不仅仅是调试符号.优化级别是一个例子,溢出检查是另一个例子.据我所知,除了查看 Cargo 和 Rust 源代码之外,没有完整的更改列表.

Switching between debug mode and release mode can change more than just debug symbols. The level of optimization is one example, overflow checking is another. To my knowledge, there's no complete list of what changes, other than reviewing the Cargo and Rust source code.

另见:

  • 使用cargo时如何获取带有调试信息的发布版本?
  • 如何在启用溢出检查的情况下编译和运行优化的 Rust 程序

更多推荐

调试符号会影响 Rust 的性能吗?

本文发布于:2023-11-25 14:27:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630122.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   性能   Rust

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!