学习如何编写延迟关键的快速 C++/Java/C# 代码的最佳方法是什么?
谁能给我一些关于学习如何进行极低延迟编程的最佳方法的指导?我有很多编程书籍,但我从未见过一本专注于(或帮助)编写极快代码的书籍。或者书籍不是前进的最佳途径吗?
专家的一些建议将不胜感激!
编辑:我想我更多地指的是CPU/内存限制。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
【C++程序员】:
超低延迟编程很难。比人们刚开始走上这条路时想象的要困难得多。您可以使用一些技术和“技巧”。例如 IO 完成端口、多核利用率、高度优化的同步技术、共享内存。这个清单永远持续下去。 (编辑)它并不像“代码配置文件重构重复”那么简单,因为您可以编写健壮且快速的优秀代码,但永远不会是真正的超低延迟代码。
不幸的是,据我所知,没有任何一种资源可以向您展示它是如何完成的。专门从事(并且擅长)超低延迟代码的程序员是业内最优秀且经验最丰富的程序员。并且有充分的理由。因为如果有成为一名优秀的低延迟程序员的灵丹妙药,那就是:您必须对所有事情都了解很多。而这些知识并不容易获得。这需要数年(数十年?)的经验和不断的学习。
就研究本身而言,以下是我认为出于某种原因有用或特别有洞察力的几本书:
[C++ programmer]:
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.
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:
我的建议是了解 C++/Java/C# 的工作原理,并大致了解它如何转换为机器级指令。有些手术比其他手术更昂贵。高级语言中的一小段代码片段会翻译成一大堆机器指令(通常比您想象的要多)。
此外,请务必学习各种数据结构、它们的优点以及它们在各种情况下的性能特征 。问题大小。为问题选择正确的数据结构可以极大地提高执行速度。
My advice would be to learn how C++/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.)
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.
从学习汇编开始。然后,如果您要使用 Java 或 .NET 工作,请学习它们的解释字节码。一旦您了解了这一点,您就需要了解您正在使用的语言以及您正在使用的编译器。继续沿着这条路走下去,您将收集一些知识,例如 VC++ 和 GCC 三元运算符 (?:) 如何导致创建临时值,而等效的 if 语句则不会。
然后大约 10 年后,您将能够编写非常好的低延迟代码。
不幸的是,没有快速的方法来学习这一点。
学习C++的好书:
有效的C++
更有效的 C++
卓越的 C++
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.
Then after about 10 years you'll be able to write pretty good low-latency code.
Unfortunately there is no quick way to learn this.
Good books to learn about C++:
Effective C++
More Effective C++
Exceptional C++