学习如何编写延迟关键的、快速的 C++/Java/C# 代码的最佳方式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4810835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:07:51  来源:igfitidea点击:

Best way to learn how to write latency-critical, fast C++/Java/C# code?

c#javac++low-latency

提问by Tom

Could anyone give me some pointers as to the best way in which to learn how to do very low latency programming? I have many programming books but I've never seen one which focused (or helped) on writing extremely fast code. Or are books not the best way forward?

谁能给我一些关于学习如何进行极低延迟编程的最佳方式的指示?我有很多编程书籍,但我从未见过专注(或帮助)编写极快代码的书籍。或者书籍不是最好的前进方式?

Some advice from an expert would be really appreciated!

专家的一些建议将不胜感激!

EDIT: I think I'm referring more to CPU/Memory bound.

编辑:我想我更多地指的是 CPU/内存限制。

回答by John Dibling

[C++ programmer]:

【C++程序员】:

Ultra-low-latency programming is hard. Much harder than people suspect when they first start down the path. There are some techniques and "tricks" you can employ. Like IO Completion ports, multi core utilization, highly optimized synchronization techniques, shared memory. The list goes on forever. (edit) It's not as simple as "code-profile-refactor-repeat" because you can write excellent code that is robust and fast, but will never be truly ultra-low latency code.

超低延迟编程很难。比人们第一次踏上这条路时所怀疑的要困难得多。您可以使用一些技巧和“技巧”。像 IO Completion 端口、多核利用率、高度优化的同步技术、共享内存。这个名单永远持续下去。(编辑)它不像“代码配置文件重构重复”那么简单,因为您可以编写强大且快速的优秀代码,但永远不会是真正的超低延迟代码。

Unfortunately there is no one single resource I know of that will show you how it's done. Programmers specializing in (and good at) ultra low-latency code are among the best in the business and the most experienced. And with good reason. Because if there is a silver bullet solution to becoming a good low-latency programmer, it is simply this: you have to know a lot about everything. And that knowledge is not easy to come by. It takes years (decades?) of experience and constant study.

不幸的是,我所知道的没有一种资源可以向您展示它是如何完成的。专攻(并擅长)超低延迟代码的程序员是业内最优秀的,也是最有经验的。并且有充分的理由。因为如果要成为一名优秀的低延迟程序员,有什么灵丹妙药的解决方案,那就是:你必须对一切都了如指掌。而这些知识并不容易获得。这需要多年(几十年?)的经验和不断的学习。

As far as the study itself is concerned, here's a few books I found useful or especially insightful for one reason or another:

就研究本身而言,以下是我认为有用或特别有见地的几本书,出于某种原因:

回答by Zach Johnson

My advice would be to learn howC++/Java/C# works and get a general idea of how it translates into machine level instructions. Some operations are more expensive that others. A little code snippet in a high-level language translates into a whole bunch of machine instructions (often more than you would think.)

我的建议是要学会如何C ++ / Java的/ C#的作品,并得到了它如何转化为机器级指令的总体思路。有些操作比其他操作更昂贵。高级语言中的一小段代码可以转换为一大堆机器指令(通常比您想象的要多)。

Also, be sure to learn the various data structures, what they are good for, and their performance characteristics for various problem sizes. Choosing the correct data structure for the problem can do wonders for execution speed.

此外,一定要了解各种数据结构、它们的用途以及它们在各种问题规模下的性能特征。为问题选择正确的数据结构可以为执行速度带来奇迹。

回答by Beanz

Start by learning assembly. Then if you're going to work in Java or .NET learn their interpreted bytecode. Once you've gotten that far you need to understand the language you are working in, and the compiler you're working on. Keep on that path and you'll collect bits of knowledge like how with both VC++ and GCC ternary operators (?:) result in creation of temporary values whereas an equivalent if statement will not.

从学习汇编开始。然后,如果您打算使用 Java 或 .NET 学习它们的解释字节码。一旦你走得那么远,你就需要了解你正在使用的语言,以及你正在使用的编译器。继续走这条路,你会收集到一些知识,比如如何使用 VC++ 和 GCC 三元运算符 (?:) 导致创建临时值,而等效的 if 语句则不会。

Then after about 10 years you'll be able to write pretty good low-latency code.

然后大约 10 年后,您将能够编写非常好的低延迟代码。

Unfortunately there is no quick way to learn this.

不幸的是,没有快速的方法来学习这一点。

Good books to learn about C++: Effective C++ More Effective C++ Exceptional C++

学习 C++ 的好书:Effective C++ More Effective C++ Exceptional C++