I recently tried to optimize some code by using parallel processing, putting two cores to work on the problem instead of one.

For whatever reason, it didn't work. I don't know why, but I doubt much can be done about the reason why it didn't work. On the other hand, posting the failure might save someone else the effort in similar situations, and I'd be interested in thoughts from experts of why it didn't work.

To be specific, this is the code that didn't work out (that is, the slow parallel version is commented out):

  int bits2 = b2.GetBits();
  if ( bits2 < 0 ) break;
  int bits3 = b3.GetBits();  

  // Version which computes bits2 and bits3 in parallel - unfortunately it seems to run slower not faster.
  // Task<int> t2 = Task<int>.Factory.StartNew( () => { return b2.GetBits(); } );
  // int bits3 = b3.GetBits(), bits2 = t2.Result; 

So...is this ok for Code review, or not? If not, do you know of a better place?

  • 1
    \$\begingroup\$ When you say the code didn't work, do you mean there was an error, or that you didn't get the performance improvement you expected. If it is the former, you should probably be posting on Stack Overflow. If it is the latter, I think it can be posted here. \$\endgroup\$
    – Blackwood
    Jan 26, 2019 at 3:08
  • \$\begingroup\$ The latter, there was no error, but it executed slower rather than faster as I hoped. I never tried using parallel processing before, so I was a bit disappointed. It's a long memory intensive calculation of the number of bits in a compressed block. \$\endgroup\$ Jan 26, 2019 at 13:35

1 Answer 1



So, here's the thing about your question: it sounds like a case of a A vs. B problem, that is very subjective as to whether it's on-topic or not, but, generally, we lean towards the side of on-topic.

But, Code Review is generally for a "anything and everything" query -- that is, "I have this code, where might I do something better?" You can ask about focus points, but usually something along the lines of "I would appreciate any thoughts on <x> particularly."

Yours sounds like a case of "Why is this code slow?" To which, we have a Meta question: Are questions about performance on-topic?, to quote:

If a question specifically restricts the answer to a particular area like performance and is not interested in a general code review, it is IMHO too narrow in scope for this site.

Even Jeff Atwood agreed in a comment:

I agree the answer is yes, but taken too far this would be the micro benchmarking code golf site which is not the intent.

Should you want a general review, now things are looking more promising.

The second problem I see here is that the code is very short, simple, and it isn't clear what the goal is. We need an explicit goal, not a "I have code that does some XOR's, how do I do that better?" We need to know why you are doing the XOR's, because there might be a better way to do those.

As an example, the very first question I asked here was improperly phrased: Massive 'switch' Optimization - Hundreds of simple/small 'case' Statements, to which it was edited: Removing accents from certain characters, because it was not the switch statement that was my problem, but the underlying use of it: the accent removal.

So, you'll want to include more context about why you are doing what you are doing, because we may be able to help you further there.

All-in-all: you can make this on-topic, but chances are that as-it-stands, it would not be so.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .