4 ms·
I came to the comments section to ask the same question. I've always liked the idea of reflection but avoided it because of performance scares (and usually I ca
by laumars 11y ago
I came to the comments section to ask the same question. I've always liked the idea of reflection but avoided it because of performance scares (and usually I can solve the problem another way).
Since we're discussing the performance footprint of regular expression libraries, it's also worth mentioning how slow even just running the base regexp library can be. For example, the email example could also be written without regex:
indices := strings.Split("joe@example.com", "@")
fmt.Println("Name:", indices[0])
fmt.Println("Domain:", indices[1])
( https://play.golang.org/p/ZezcoBjc9v https://play.golang.org/p/ZezcoBjc9v )
Obviously the above code doesn't do any sanity checks - which is where regular expressions can often make things easier. But the above would run a lot faster than a regexp pattern match.