4 ms·
This is a pretty shallow post complete with code samples as screenshots rather than text. The “expert level” technique uses an unbounded number of threads rath
by orf 4y ago
This is a pretty shallow post complete with code samples as screenshots rather than text.
The “expert level” technique uses an unbounded number of threads rather than utilising a thread pool.
Using concurrent objects here also seems a waste - why pay for the locking overhead? The set of all states is quite small - just create a unique set of states, pre-fill the “taxMap” in parallel, then launch a number of tasks to calculate the totals. You probably don’t even need to do the final calculation in parallel as it’s super simple.
With the approaches listed here you are calling GetSalesAndTax multiple times for the same state.
The author hasn’t realised that the essence of the problem can be distilled down to needing a call a single expensive function with a single argument once and collect the results into a hashmap.
The use of a concurrent bag is also a waste - just return the total from the task? You could return a tuple of (unique ID, total) to allow you to associate the result with a specific migrant.
- nesarkvechnep 4y agoThe author has “over 20+ years’ experience in software development”.
- TheLoafOfBread 4y agoI guess author is also counting there high school and college
- hayley-patton 4y agoA wise man once told me "some people don't have ten years of experience, they have one year of experience ten times."