3 ms·
Most conversions are things like casts to enum types or aliases I think, which never are O(n), like: dur := time.Second * time.Duration(2) headers
by TheDong 2y ago
Most conversions are things like casts to enum types or aliases I think, which never are O(n), like:
dur := time.Second * time.Duration(2)
headers := http.Header(map[string][]string{})
httpDir := http.Dir(filepath.Join(parts...))
In all of these cases, it's just a type-cast which is zero-cost, and I think that's what makes it feel surprising that casting between strings/runes specifically incurs more significant computation than any other cast.
- foldr 2y agoAll of those are copies and hence O(n) in the size of the value copied. This is hidden somewhat because your examples use constants and literals. (As numeric constants aren’t typed in Go the first example arguably doesn’t involve a copy, but the rest do.)