- C# (.NET v6) vs Go - Exceptions
- C# (.NET v6) vs Go - JSON
- Go - Method Invocation
- C# code:
- C# results:
- Go code:
- Go results:
- C# 10ns vs 11us - Try not to use exceptions in the hot paths of your code.
- Go 4ns vs 150ns - Panic in Go is generally for non user defined errors. All others are simply values passed via the
error
interface.
- C# code:
- C# results:
- Go code:
- Go results:
The new JSON serializer in .NET 6 with code generation is about the same speed as the default in Go. Easyjson also uses the code generation aproach and is 4 times faster.
- Go code:
- Go results:
The method invocation on type vs interface vs empty interface with type switch or type assertion have little to no difference in performance. The fastest seems to be to pass a struct as interface. Maybe the method table is smaller in this case ๐คทโโ๏ธ.