by shilangyu · 3y ago · 0 comments
The Go version that was presented isn't equivalent though. In Go you are accepting an interface directly which will hide the value under some fat pointer for dynamic dispatch, in c++ you are using generics to monomorphise the function to specific types. If you want to compare the implementations fairly you should've used Go generics:
func Count[T IntIterable](i T) (count int) {Some reading: https://github.com/golang/proposal/blob/master/design/generi... https://planetscale.com/blog/generics-can-make-your-go-code-...
Considering the progress Go compiler has gone through, I think it's reasonable to expect the optimized implementations will come few versions down the road.