Go和Python的非同步效能那個對於後端更好?

時間 2021-06-02 23:46:58

1樓:euphoria

如果單核的話,通道可以最大化效能,如果多核的話,無論哪種語言都有難度。go 語言也很容易掉落坑里,而且並不是所有業務都適合非同步和併發。

There's an absolutely amazing library for Haskell called Haxl, that automatically tracks the data dependencies of your network requests and batches them and runs them asynchronously as long as they don't overlap. It's something that shows the power of computational abstractions like monads and it's not something that has a, ahem, parallel in any other language, as far as I know. At least, not for IO.

We've had this exact ability in the CPU for a long, long time. The CPU tracks the data dependencies of computations and will parallelize them wherever possible.

The reason data dependencies matter is that the CPU doesn't just execute one instruction at a time. As long as two instructions don't share a register they can safely be run simultaneously, so the CPU does so. This is essentially free parallelism without the need for locks, work queues or anything that affects your architecture at all, so you would be crazy not to take advantage of it.

Parallelizable computation also lends itself well to autovectorization, which is the process where the compiler realizes that you're doing the same thing to multiple different values and converts it to a special instruction that, well, does the same thing to multiple different values.

For example, the compiler could translate the following numerical code:

(a1 + a2) + (b1 + b2) + (c1 + c2) + (d1 + d2)

into just one instruction that executes all four subexpressions as fast as a single addition.

%intermediate-value = add-vectors [%a1 %b1 %c1 %d1] [%a2 %b2 %c2 %d2]

sum-parts %intermediate-value

RUST 和 GO那個效能更好?

Rust在執行效能上各個方面的效能都要比Go好不少,Rust也沒有GC,所以不存在Stop the world 問題,再加上Rust更容易做一些底層優化 例如Rust可以通過 repr align 64 這個屬性標記強制進行記憶體對齊,在需要命中CPU快取的場景是非常有用的,具體見 這篇文章 不過效...

為什麼GO語言的效能還不如C

你不能用這麼粗暴的用 for 迴圈來測試效能,然後下論斷,而且你 Golang 和 C 的版本 執行環境都沒有說,Golang 這幾年提公升很大的。最後.題主建立 map 的時候都沒有設定 capacity,建議設定一下再看,go 這樣不設定的話挺影響效能的。 gao xinge 雖說比較語言效能招...

非同步電機和同步電機中的 非同步 與 同步 指的是什麼?

小夜的花豆 交流電機分為兩種 1 感應電機 非同步電機 簡單理解的話,非同步的理解其實可以用能量守恆原則去解釋。輸入三相交流電的定子線圈形成旋轉磁場,拖動 鼠籠式轉子轉動。拖的永遠趕不上拉的。2 同步電機 也按照上面的理解,輸入三相交流電的定子線圈產生旋轉磁場,但是轉子不是普通的轉子啦。而是磁鐵磁鐵...