为 another internet forum quote 致歉,但我觉得这很有趣,想问一下:
C++ is faster if you chuck the "safety" features of programming languages and avoid things like STL, and Boost. In raw bytes to bytes C++ is faster, but then again so is C.
The moment you add the baggage of STL, and Boost you are slower than well written C# code. The advantage that the C# JIT and Java jit have is that those safety features are well optimized. C++ safety features rely on the optimization of the compiler.
Thus if you are not careful with your STL, and Boost code you will have a lame duck of an application.
我同意取消安全功能,但我看过很多高频招聘广告,他们都要求有 Boost 经验。 Boost 对生成快速代码肯定不是坏事吗?或者这个人只是在理论上说如果你只是在字节级别进行操作会更快?
编辑:引用是关于 STL 和 Boost,因此我添加了 STL 标签。
最佳答案
否
boost 和 C++ 标准库用于生成极快的生产实现。当然,在特定场景中可以改进这些实现——这类似于在您知道自己的执行与通用分配器有何不同以及如何针对该用途进行优化时编写自己的分配器。因此,当然可以分析问题并生成比通用实现(或 boost )更快的优化实现。
当然,任何库也可能被滥用,这可能会导致执行受损。简而言之,boost(大量库)实现是快速实现的绝佳起点。如果您需要它比 boost 更快,请确定问题并加以改进。
许多 C++ 开发人员关心性能;一般来说,比其他语言更多。 boost 通常受到好评,经过同行评审,并且实现用于测试和形成标准库功能的基础。
感谢贾斯汀让我分享他对已结束问题的回答: -- Seth
Quite the opposite.
Boost is not about safety belts.
Boost is about high level software components, with a high level of abstraction This avoids the usual 'library lock-in' seen with other frameworks/libraries1.
For example, your Boost Graph library does not require you to switch data structures at all: you can use/adapt any data structure that performs well for your application. In the worst case, you might have to write a traits class to help Boost with the interpretation; It is precisely this trait (common to modern template libraries) that makes Boost perform like nothing else in practice: there won't be as much library impedance mismatch. This is directly in line with C++11's new concepts around threading and move semantics: preventing even the most elementary cases of data copying.
Also, all these libraries honour your own allocator implementations, allowing for unsurpassable memory management performance. You can aligned 128bit int vectors in C# - but you'll have to jump through many many hoops2 and, there is no way you can ever make it work with the framework API's.
In C++ you pay only for what you use, and Boost is entirely in that spirit.
Mmmm I think I haven't quite stressed the point enough yet, but I'm done for now.
Let me close by looking at it from the other side: in C# it is much harder to write performant code, because it is much harder to see what's going on behind the scenes.
Once you drop behind the scenes (unsafe mode, IL code) you'll arguably be less safe than in C++, because in C++ there is a transparent policy of what happens where and how. In C# you can't even trust an
int*that you got one line ago (because the Garbage Collector might have moved your cheese); There is no telling what the compiler and or the JIT engine will make of your nice generic code3.In short: you can write bad code just anywhere, but Boost cannot be blamed. STL can only be blamed for insane raw performance4.
1PoCo, Qt, MFC, WTL, whatnot....
3Including numerous areas that are close to pathetic and violate the 'Principle Of Least Surprise' in a big way (example
comingwhen blog back online)4That
std::copywill be statically translated in the best implementation based on SSE4, MOVSW or just plain memcpy that money can buy, and yet you don't have to even write a single letter different from copying aistreamto aset, so to speak.
关于c++ - Boost/STL 在高性能计算方面是否慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7880024/
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
这个问题在这里已经有了答案:Checktoseeifanarrayisalreadysorted?(8个答案)关闭9年前。我只是想知道是否有办法检查数组是否在增加?这是我的解决方案,但我正在寻找更漂亮的方法:n=-1@arr.flatten.each{|e|returnfalseife
这里是Ruby新手。完成一些练习后碰壁了。练习:计算一系列成绩的字母等级创建一个方法get_grade来接受测试分数数组。数组中的每个分数应介于0和100之间,其中100是最大分数。计算平均分并将字母等级作为字符串返回,即“A”、“B”、“C”、“D”、“E”或“F”。我一直返回错误:avg.rb:1:syntaxerror,unexpectedtLBRACK,expecting')'defget_grade([100,90,80])^avg.rb:1:syntaxerror,unexpected')',expecting$end这是我目前所拥有的。我想坚持使用下面的方法或.join,
我有一个包含多个键的散列和一个字符串,该字符串不包含散列中的任何键或包含一个键。h={"k1"=>"v1","k2"=>"v2","k3"=>"v3"}s="thisisanexamplestringthatmightoccurwithakeysomewhereinthestringk1(withspecialcharacterslike(^&*$#@!^&&*))"检查s是否包含h中的任何键的最佳方法是什么,如果包含,则返回它包含的键的值?例如,对于上面的h和s的例子,输出应该是v1。编辑:只有字符串是用户定义的。哈希将始终相同。 最佳答案
我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查
我的日期格式如下:"%d-%m-%Y"(例如,今天的日期为07-09-2015),我想看看是不是在过去的七天内。谁能推荐一种方法? 最佳答案 你可以这样做:require"date"Date.today-7 关于ruby-检查日期是否在过去7天内,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/32438063/
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我们的git存储库中目前有一个Gemfile。但是,有一个gem我只在我的环境中本地使用(我的团队不使用它)。为了使用它,我必须将它添加到我们的Gemfile中,但每次我checkout到我们的master/dev主分支时,由于与跟踪的gemfile冲突,我必须删除它。我想要的是类似Gemfile.local的东西,它将继承从Gemfile导入的gems,但也允许在那里导入新的gems以供使用只有我的机器。此文件将在.gitignore中被忽略。这可能吗? 最佳答案 设置BUNDLE_GEMFILE环境变量:BUNDLE_GEMFI
这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub