Why does adding concurrency slow down this golang code?

后端 未结 4 1288
天涯浪人
天涯浪人 2020-12-12 19:31

I\'ve got a bit of Go code that I\'ve been tinkering with to answer a little curiosity of mine related to a video game my brother-in-law plays.

Essentially, the cod

4条回答
  •  暖寄归人
    2020-12-12 20:00

    Testing your code on my Linux quad core i7 laptop I get this

    Here is a Google Spreadsheet

    Screenshot of Google Spreadsheet

    This shows that under Linux at least the scaling is very nearly linear per core.

    I think there may be two reasons why you aren't seeing this.

    The first is that your macbook air only has 2 real cores. It has 4 hyperthreads though which is why it reports 4 as max cpus. A hyperthread typically only gives an extra 15% performance over a single core rather than the 100% you might expect. So stick to benchmarking 1 or 2 CPUs only on the macbook air!

    The other reason might be OS X thread performance compared to Linux. They use different threading models which may be affecting performance.

提交回复
热议问题