TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

New Rust hash table leads Benchmarks Game

198 点作者 joseraul大约 8 年前

17 条评论

mbrubeck大约 8 年前
In other Rust&#x2F;benchmarksgame news, I just submitted a simple fix to the Rust program for &quot;reverse-complement&quot; that makes it faster than the fastest C++ program, on my computer. The old version was spending 2&#x2F;3 of its time just reading the input into memory, because it wasn&#x27;t allocating a large enough buffer up front.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;TeXitoi&#x2F;benchmarksgame-rs&#x2F;pull&#x2F;44" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;TeXitoi&#x2F;benchmarksgame-rs&#x2F;pull&#x2F;44</a><p>I&#x27;m also working on some additional changes that make it even faster than the C version (again, on my computer) by improving how it divides work across CPUs:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;TeXitoi&#x2F;benchmarksgame-rs&#x2F;pull&#x2F;46" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;TeXitoi&#x2F;benchmarksgame-rs&#x2F;pull&#x2F;46</a><p>These improved Rust programs have not yet been added to the benchmarksgame site. Previous entries are ranked at:<p><a href="http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;performance.php?test=revcomp" rel="nofollow">http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;performance.php...</a><p>Minor improvements to the Rust programs for &quot;mandelbrot&quot; and &quot;binary-trees&quot; are also awaiting review!
评论 #13746832 未加载
评论 #13749931 未加载
igouy大约 8 年前
Previously std::collections::HashMap was used with the default hash function --<p>[46.03 secs] <a href="http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?test=knucleotide&amp;lang=rust&amp;id=1" rel="nofollow">http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?tes...</a>)<p>and then the hash function was changed to FnvHasher --<p>[17.10 secs] <a href="http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?test=knucleotide&amp;lang=rust&amp;id=2" rel="nofollow">http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?tes...</a><p>and then better use of quad core with futures_cpupool --<p>[9.44 secs] <a href="http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?test=knucleotide&amp;lang=rust&amp;id=3" rel="nofollow">http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?tes...</a><p>and now use of std::collections::HashMap has been replaced with an experimental hash table inspired by Python 3.6&#x27;s new dict implementation --<p>[5.30 secs] <a href="http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?test=knucleotide&amp;lang=rust&amp;id=4" rel="nofollow">http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?tes...</a><p><i>afaict</i> comparing #4 to #5 is all about differences between that experimental hash table and std::collections::HashMap --<p>[9.14 secs] <a href="http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?test=knucleotide&amp;lang=rust&amp;id=5" rel="nofollow">http:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;program.php?tes...</a>
评论 #13746855 未加载
评论 #13748277 未加载
stcredzero大约 8 年前
Java is showing quite impressive numbers! 50% overhead over native C implementations was often cited as a good guess for the ultimate efficiency of JIT code generation back in the <i>Self</i> Hotspot days.<p>People who were trying to castigate Go early on as having &quot;Java-like speeds&quot; were really just showing their ignorance of the state of the art of JIT compilation for managed languages and the JVM. Such outdated folk knowledge of performance in the programming field seems to be a constant over the decades. (Programmers have had such distorted views since the mid 80&#x27;s at least.) Maybe this kind of knowledge needs to be a used in job interview questions for awhile? Very soon, people will just memorize such trivia for interviews, but it would serve to squash this form of folk programming &quot;alternative fact.&quot;
评论 #13748209 未加载
评论 #13747321 未加载
评论 #13747349 未加载
评论 #13747826 未加载
评论 #13749504 未加载
评论 #13747335 未加载
chris_overseas大约 8 年前
It seems to me that there are a lot of apples-to-oranges comparisons here? Some implementations are using the language&#x27;s standard library hashtable implementation while others are using 3rd party version (with different algorithms and data structures across all of them), some are using multiple threads while others are single threaded etc. As a result, I wouldn&#x27;t read too much into the rankings you see here.
评论 #13747001 未加载
评论 #13745075 未加载
评论 #13744947 未加载
评论 #13745583 未加载
评论 #13744923 未加载
评论 #13745051 未加载
评论 #13749600 未加载
评论 #13744959 未加载
galangalalgol大约 8 年前
When SIMD goes stable rust may dominate that game. Still wish they would use clang so it was apples to apples with c and c++. Edit: actually I wish they would add clang for those languages and leave GCC for comparison. Then I&#x27;d want FORTRAN to add gfortran for the same reason.
评论 #13745637 未加载
评论 #13744678 未加载
评论 #13745090 未加载
评论 #13746000 未加载
richard_todd大约 8 年前
Just FYI in case it happens to others: I was confused because the page I get shows Rust coming in fourth. I had to reload it&#x2F;re-sort the columns a couple times to see the new Rust #4 entry.
crb002大约 8 年前
LLVM IR could squeeze out some more. I should take a crack at it. Did something similar to show DuPont why Criterion rocked.
评论 #13744641 未加载
评论 #13745542 未加载
评论 #13744639 未加载
saurik大约 8 年前
&gt; Some language implementations have hash tables built-in; some provide a hash table as part of a collections library; some use a third-party hash table library. (For example, use either khash or CK_HT for C language k-nucleotide programs.) The hash table algorithm implemented is likely to be different in different libraries.<p>&gt; Please don&#x27;t implement your own custom &quot;hash table&quot; - it will not be accepted.<p>&gt; The work is to use the built-in or library hash table implementation to accumulate count values - lookup the count for a key and update the count in the hash table.<p>The C++ implementation is thereby testing an old version of a non-standard extension of libstdc++ that I had never heard of and which was likely contributed once by IBM and never really looked at again (by either maintainers <i>or users</i> ;P), while the C implementation is testing the specified khash library, which is apparently something a number of people actively contribute to and attempt to optimize, giving it some notoriety.<p>If I were to do this in C++, and I wasn&#x27;t allowed to use my hash table, I would almost certainly not be using __gnu_pbds::cc_hash_table&lt;&gt;. If I were to just want to use something &quot;included&quot;, I would use the C++11 std::unordered_map&lt;&gt; (note that this code is compiled already as C++11). But we all know the STL is designed for flexibility and predictability, not performance, and the culture of C++ is &quot;that&#x27;s OK, as if you actually care about performance no off-the-shelf data structure is going to be correct&quot;. If I decided I wanted speed, I know I&#x27;d want to check out Folly, and I might even end up using khash.<p>Reading other comments, what happened here is the Rust version is now using some &quot;experimental&quot; hash table based on ongoing work to optimize the Python 3000 dict implementation. This is just not a useful benchmark. What we are benchmarking is &quot;how maintained is the implementation&#x27;s built in hash table and is it tunable for this particular workload&quot;.<p>That&#x27;s why you should not be surprised to see Java doing so well: the code actually being written here is just some glue... your programming language has to be incompetent to do poorly at this benchmark (especially as many commenters here are using a &quot;within a power of 2&quot; rule of thumb). There are even multiple listings for the Java one, and the one that is faster is using it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap?!?<p>What we really should be asking here is: why is <i>any</i> language doing &quot;poorly&quot; in this benchmark? It just isn&#x27;t surprising that Rust is competitive with C&#x2F;C++, nor is it surprising that Java is also; what <i>is</i> surprising is that Swift, Go, Haskell, and C# are not, and so I bet the issue is something (such as &quot;is allocating memory for a thing which is not required&quot;) that can be trivially fixed for each (though by the rules of engagement, it might... or might not :&#x2F; as Java &quot;cheated&quot;, right? ;P... require a minor fix upstream).<p>I mean, since the &quot;work&quot; explicitly is not &quot;write a hash table using nothing but primitives from this language&quot;, there is no particular reason why Perl and Python (which is using a non-destructive array .replace, which is likely <i>brutal</i>... again: I bet this is almost always a benchmark of ancillary memory allocations) should be doing as poorly as they are: if we all made &quot;optimize for this benchmark&quot; a top priority for a weekend hackathon, I bet we could get every open source language to nail this under 25s. But do we care?
评论 #13749720 未加载
评论 #13779958 未加载
评论 #13749667 未加载
insulanian大约 8 年前
I&#x27;m not a system programmer, but it makes me very happy to see Rust taking off, with all its potential to, hopefully, replace currently most used unsafe system languages.
makmanalp大约 8 年前
Is there something fishy going on with the NaiveHashMap here? What&#x27;s happening?<p><pre><code> impl Hasher for NaiveHasher { fn finish(&amp;self) -&gt; u64 { self.0 } fn write(&amp;mut self, _: &amp;[u8]) { unimplemented!() } fn write_u64(&amp;mut self, i: u64) { self.0 = i ^ i &gt;&gt; 7; } }</code></pre>
评论 #13746835 未加载
评论 #13745922 未加载
评论 #13747347 未加载
santaclaus大约 8 年前
Cool! Is Rust&#x27;s hash table open addressed?
评论 #13745029 未加载
geodel大约 8 年前
It is new Rust hash table from external crate.
评论 #13744840 未加载
评论 #13745098 未加载
jeffdavis大约 8 年前
Does this have anything to do with: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13742865" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13742865</a> ?
评论 #13745415 未加载
kcdev大约 8 年前
I&#x27;m really curious what this benchmark would be for JavaScript V8? Anyone have the time to recreate the same functionality to test in Node?
评论 #13747696 未加载
vegabook大约 8 年前
quite a decent perf from the ML family at around 19 seconds (F# and Ocaml). Top of the functionals, at least, twice as fast as Haskell.<p>Also look how ginormous the binaries are for all the VM languages. Kinda would have thought it would be the opposite what with not needing to link in as much runtime?
评论 #13744831 未加载
评论 #13744885 未加载
snakeanus大约 8 年前
Does anybody know what happened to the image charts like this one for example? <a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20121218042116&#x2F;http:&#x2F;&#x2F;shootout.alioth.debian.org&#x2F;u64&#x2F;ats.php" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20121218042116&#x2F;http:&#x2F;&#x2F;shootout.a...</a><p>This was my favourite feature of the benchmarks game.
评论 #13756561 未加载
gigatexal大约 8 年前
The rust version is using multiple cpus using a pool concept (which looks a lot like the multiprocessing module from python so kudos there). But the C version is single threaded from what I can tell. So rust is safe but threaded to be faster than single threaded C which isn&#x27;t that much slower. Hmm...
评论 #13744880 未加载
评论 #13744876 未加载
评论 #13744830 未加载
评论 #13745060 未加载