Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • This seems to knock ~1/3 off the original cost for n=1M. You can strip another ~1/5 or so by using ValueTuple instead of Tuple, but it's still ~2times slower than a serial loop. (Disclaimer: didn't run many repeats, and this is on my particular machine with my particular random data set). Commented Aug 7, 2020 at 18:01
  • ... though, this does get faster if you add an AsParallel (not as fast as serial in my silly little test though) Commented Aug 7, 2020 at 18:04
  • Regarding that last bit, my tests suggest the opposite: that it will actually be faster to build the reverse dictionary from the forward dictionary rather than building both at the same time, but I've not properly tested this, and it is an interesting question. Commented Aug 7, 2020 at 19:01
  • Yes was thinking about replacing the Tuple with a Value.Tuple too, but from what I found the Tuple is supposed to be slightly faster except when used as key. I really doubt that the iteration using for is 2 times faster. Indeed Enumerator has some overhead opposed to pure index based iteration, but the costs shouldn't have a factor of 2 and are generally neglectable.Also the workload is too small for parallel partitioning. The overhead introduced by threading and synchronization is too expensive. Commented Aug 7, 2020 at 19:59
  • Sequential data is generally difficult to parallelize and requires merging which also impacts the efficiency. I mean it all depend on n. If n is big enough you can parallelize. When you can determine the pivot n, you can offer a dynamic hybrid solution. But for small n (and n=1M is still small in this context or workload) this shouldn't pay off. The problem is the nested collections. I think there is not much you can do. The real improvement would be to find a better data structure, that allows two way lookup like a bi-directional tree (undirected graph). Commented Aug 7, 2020 at 19:59